fix: keep prompt input inert during Safari IME composition#38728
Open
powoct wants to merge 5 commits into
Open
fix: keep prompt input inert during Safari IME composition#38728powoct wants to merge 5 commits into
powoct wants to merge 5 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Production Safari testing showed the earlier Enter guard was not enough: every composition keystroke still went through onKeyDown dispatch and the onKeyUp/onPointerUp cursor sync, which makes Safari abort the composition and split it into per-letter micro compositions. The confirming Enter then arrives as a plain keyCode 13 long after compositionend and no guard can recognize it, so the raw pinyin gets submitted. Make the editor do nothing while a composition is active (and during the 100ms window after compositionend): skip keydown dispatch, cursor sync, input handling, and editor DOM rewrites, then reconcile state once from the DOM on compositionend. This keeps the composition as a single segment so the confirming Enter reports keyCode 229 and is caught by the guard. Co-authored-by: Cursor <cursoragent@cursor.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.
Issue for this PR
Closes #38674
Type of change
What does this PR do?
In Safari, typing CJK text in the web app prompt input misbehaves in two ways: the IME composition gets aborted mid-input, and the Enter that confirms a candidate submits the message with the raw pinyin still in it.
Two causes, fixed in order:
Safari fires
compositionendbefore the confirming Enter keydown, so that keydown reportsisComposing=false. The first commits add a guard that treats any key event within 100ms ofcompositionend(tracked withperformance.now()) as part of the IME confirmation, in both the v1 (packages/app) and v2 (packages/session-ui) editors.That guard alone was not enough on a production deployment: the v2 editor still ran
dispatch/setStateon every keydown and read/wrote the selection on keyup/pointerup while composing. Safari reacts by aborting the composition after every letter, sonihaobecomes five one-letter compositions and the final Enter arrives as a plainkeyCode=13long after anycompositionend— nothing left for the guard to recognize. The last commit makes the v2 editor completely inert while a composition is active (and during the 100ms window after it): no keydown dispatch, no cursor sync, no input handling, no editor DOM rewrites. State is reconciled once from the DOM oncompositionend. With the editor inert, Safari keeps the composition as a single segment, the confirming Enter reportskeyCode=229, and the existing guard catches it.Note: Enter committing the raw romaji (instead of 你好) is macOS Pinyin design — Space selects the candidate. The bug was that the app submitted the message on that Enter.
How did you verify your code works?
nihao+ Enter no longer submits and the text stays in the box,nihao+ Space commits 你好, Japanese live conversion with multi-segment auto-commit is not interrupted, and plain-English Enter / Shift+Enter behavior is unchanged. Chrome regression-tested with the same IMEs.bun test machine.test.tsinpackages/session-ui(13 pass, including 2 new IME assertions) andbun typecheckacross the affected packages.Screenshots / recordings
No visual change; the fix only touches input event handling.
Checklist
Made with Cursor