fix(web): prevent Safari IME composition Enter from sending message#1140
fix(web): prevent Safari IME composition Enter from sending message#1140ilblackdragon merged 2 commits intonearai:stagingfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a browser-specific bug affecting Safari users who utilize CJK Input Method Editors (IMEs). It ensures that the 'Enter' key, when used to confirm IME composition, no longer prematurely sends a message, aligning Safari's behavior with other browsers like Chrome and Firefox. The fix specifically targets Safari's unique event firing order for compositionend and keydown events. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a bug on Safari where confirming IME input with the Enter key incorrectly sends the chat message. The fix introduces a check for e.keyCode !== 229, which is a sentinel value used by Safari for IME-related key events. My review focuses on improving the maintainability of this workaround by suggesting the use of a named constant and enhancing the code comment with a reference to the underlying browser bug.
| // keyCode 229 (VK_PROCESS) filters out IME-handled Enter on Safari, where | ||
| // compositionend fires before keydown leaving e.isComposing already false. |
There was a problem hiding this comment.
Since keyCode is a deprecated property, it's helpful to include a permanent reference to the browser bug that necessitates this workaround. This provides valuable context for future maintainers and makes the comment more concise.
| // keyCode 229 (VK_PROCESS) filters out IME-handled Enter on Safari, where | |
| // compositionend fires before keydown leaving e.isComposing already false. | |
| // Filter out IME composition confirmation on Safari. `isComposing` is not reliable | |
| // as `compositionend` fires before `keydown`. See https://bugs.webkit.org/show_bug.cgi?id=165004 |
| if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { | ||
| // keyCode 229 (VK_PROCESS) filters out IME-handled Enter on Safari, where | ||
| // compositionend fires before keydown leaving e.isComposing already false. | ||
| if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.keyCode !== 229) { |
There was a problem hiding this comment.
To improve readability and maintainability, consider extracting the magic number 229 into a named constant like const VK_PROCESS = 229;. This could be defined at a suitable scope (e.g., at the top of the file). The comment already helpfully mentions VK_PROCESS, and using a constant would make the code even clearer.
henrypark133
left a comment
There was a problem hiding this comment.
Review: Safari IME Enter handling looks correct
This is a tight fix for the Safari composition ordering edge case, and the change stays contained to the existing keydown path.
Positives:
- The
keyCode !== 229guard directly targets the Safari IME-confirmation path without changing normal Enter behavior. - The PR is small enough that the manual test plan is proportionate.
- Meaningful CI ran on the fork, so this is in a reasonable state to merge.
No blocking issues from my side.
Safari sets e.isComposing=false on the keydown event that ends IME composition, unlike Chrome/Firefox. This caused pressing Enter to confirm CJK input to immediately send the message. Track composition state manually via compositionstart/compositionend and guard the send condition with both e.isComposing and _isComposing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b5760e4 to
25dfc5d
Compare
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Updated the comment per the bot's suggestion — added a reference to the WebKit bug (165004) and rephrased for clarity. Skipped the named constant since VK_PROCESS is only used once and the comment already explains it. |
zmanian
left a comment
There was a problem hiding this comment.
Review: Safari IME composition Enter fix
Clean, minimal fix for a well-known Safari/WebKit bug. Adding e.keyCode !== 229 is the standard workaround.
- Safari fires
compositionendbeforekeydown, soe.isComposingis alreadyfalsewhen Enter confirms CJK input keyCode 229(VK_PROCESS) identifies IME-handled keystrokes regardless of composition state- WebKit bug reference included: https://bugs.webkit.org/show_bug.cgi?id=165004
- 3 lines changed, no risk
Title check: accurate.
LGTM.
…earai#1140) * fix(web): handle Safari IME composition Enter key Safari sets e.isComposing=false on the keydown event that ends IME composition, unlike Chrome/Firefox. This caused pressing Enter to confirm CJK input to immediately send the message. Track composition state manually via compositionstart/compositionend and guard the send condition with both e.isComposing and _isComposing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(web): improve Safari IME comment with WebKit bug reference Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…earai#1140) * fix(web): handle Safari IME composition Enter key Safari sets e.isComposing=false on the keydown event that ends IME composition, unlike Chrome/Firefox. This caused pressing Enter to confirm CJK input to immediately send the message. Track composition state manually via compositionstart/compositionend and guard the send condition with both e.isComposing and _isComposing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(web): improve Safari IME comment with WebKit bug reference Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes #1139
Problem
On Safari (macOS), pressing Enter to confirm CJK (Chinese/Japanese/Korean) IME input in the chat textarea sends the message immediately instead of just committing the composed text.
Root cause: Safari fires
compositionendbeforekeydown— the opposite of Chrome and Firefox. By the time thekeydownhandler runs,e.isComposingis alreadyfalse, so the existing guard is bypassed.Reference: WebKit bug 165004
Fix
Safari sets
e.keyCodeto229(VK_PROCESS) on everykeydownevent processed by the IME, including the confirmation Enter. This value is defined in the W3C UIEvents spec as the IME-processing sentinel and is never generated by a physical key on any keyboard layout.Impact
e.isComposingalready handles these correctly;keyCode !== 229is a no-op ✓keyCode 229is never produced by a physical key; no regression risk ✓Test Plan