[lexical] Bug Fix: Don't scroll or steal focus when an IME composition is force-committed - #8835
Draft
2wheeh wants to merge 2 commits into
Draft
[lexical] Bug Fix: Don't scroll or steal focus when an IME composition is force-committed#88352wheeh wants to merge 2 commits into
2wheeh wants to merge 2 commits into
Conversation
…n is force-committed Clicking outside the editor mid-composition makes the browser force-commit and fire compositionend. Because the commit happens before focus actually moves, the editor is still the active element, so every activeElement guard in $updateDOMSelection passes and reconciliation scrolls the caret back into view — undoing the scrolling the user just did to reach whatever they clicked. A plain contenteditable keeps its scroll position under the same gesture. Distinguish keyboard-driven commits from browser-forced ones: a commit typed by the user (Space/Enter, next-syllable, arrows) is always preceded by a keydown on the editor, and one caused by clicking away is not. When the keydown is missing, tag the update with SKIP_SELECTION_FOCUS_TAG and SKIP_SCROLL_INTO_VIEW_TAG, reusing the lastKeyDownTimeStamp heuristic $handleCompositionStart already uses. The committed text is still synced and the selection still reconciled; only the focus grab and the scroll-into-view are suppressed. Android Chrome zeroes lastKeyDownTimeStamp while composing, so the zero check leaves it unchanged. Both routes into compositionend are covered: the immediate one and Firefox's, which defers the commit to the input event that follows. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Jul 14, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
maybe the shape of $onCompositionEndImpl should change a bit (e.g. to take more parameters and handle exit a bit differently)? it looks like all of the new tagging always goes after that function so perhaps it would be easier if that function was responsible for setting the tags
…ionEndImpl Follow-up to the force-committed-composition scroll fix, addressing review feedback that the tag-setting should belong to $onCompositionEndImpl rather than trail after each of its callers. Moving the tagging inside the function — right after $setCompositionKey(null), before any exit — makes the tag follow from ending the composition instead of from each caller remembering to add it. That closes two gaps the caller-side tagging had left open, both intended: - The token-redirect path in $handleInput only tagged when it actually redirected onto a token node. An ordinary multi-character commit (the common CJK case) ended untagged. It is now tagged. - Safari's deferred 'ending-safari' commit, processed on the following keydown, was never tagged at all. It is now tagged. Because that path finishes the commit later, the compositionend timeStamp is stashed in the new InputState.compositionEndTimeStamp so the classification reads when the composition actually ended, not when we got around to it. Also separates RECENT_KEYDOWN_WINDOW from ANDROID_COMPOSITION_LATENCY. They held the same value but answer different questions — one is how late Android's keyboard delivers events, the other is whether a keystroke is behind a composition event at all — so tuning one must not silently move the other. No value change; the $handleCompositionStart site that was already asking the keydown-recency question is switched to the new name. The scroll-suppression comment now records that SKIP_SCROLL_INTO_VIEW_TAG only suppresses Lexical's own reconciliation scroll (the Chromium case), and does nothing where the browser natively scrolls the caret on commit (observed on Firefox, where a plain contentEditable jumps identically). Adds a Firefox unit test for the multi-character-commit path that the token-redirect gap left untagged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Describe the changes in this pull request
Closes #8834
Test plan
Before
Insert relevant screenshots/recordings/automated-tests
After
Insert relevant screenshots/recordings/automated-tests