[lexical] Bug Fix: Skip ZWSP insertion for format mismatch on Android Chrome#8769
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Jul 2, 2026
Comment on lines
+1335
to
+1338
| (!IS_ANDROID_CHROME && node.getFormat() !== selection.format) || | ||
| (!IS_ANDROID_CHROME && | ||
| $isTextNode(node) && | ||
| node.getStyle() !== selection.style) |
Collaborator
There was a problem hiding this comment.
This is slightly shorter if the conditions are fused (suggestion won't pass ci-check cleanly without running prettier first)
Suggested change
| (!IS_ANDROID_CHROME && node.getFormat() !== selection.format) || | |
| (!IS_ANDROID_CHROME && | |
| $isTextNode(node) && | |
| node.getStyle() !== selection.style) | |
| (!IS_ANDROID_CHROME && (node.getFormat() !== selection.format || | |
| $isTextNode(node) && | |
| node.getStyle() !== selection.style)) |
etrepum
approved these changes
Jul 2, 2026
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
On Android Chrome, Samsung Keyboard and other non-Gboard keyboards (Yandex, FUTO) cache the composing region internally. When a user toggles bold/italic during composition,
$handleCompositionStartdetects a format mismatch betweenselection.formatandnode.getFormat()and inserts a ZWSP viaCONTROLLED_TEXT_INSERTION_COMMAND. This DOM mutation triggers Samsung Keyboard'srestartInput(), which restores the cached composing text and causes duplication.The original issue (#7649) reports text duplication after toggling format on Samsung Keyboard. On our Android device the duplication didn't reproduce on the current main, but a related symptom did: typing Korean with bold enabled on Samsung Keyboard splits jamo (e.g. typing "한글" produces "ㅎㅏㄴㄱㅡㄹ" with each consonant/vowel separated). The root cause is the same — the ZWSP insertion disrupts Samsung's composing region tracking.
Fix
Guard the format and style mismatch conditions with
!IS_ANDROID_CHROMEso the ZWSP insertion is skipped on Android Chrome. The other conditions that trigger ZWSP (element anchor, non-collapsed selection,ANDROID_COMPOSITION_LATENCYtiming heuristic) remain unguarded since those handle structural cases unrelated to Samsung's caching behavior.The trade-off: toggling format during an active composition on Android Chrome Samsung Keyboard won't show the format change visually until the composition ends. The format itself is preserved correctly —
selection.formatpersists through the composition cycle and applies on the nextinsertText.Closes #7649
Test plan
pnpm vitest run --project unit— all pass, no regression.pnpm tsc --noEmitclean.LexicalAndroidChromeComposition.test.ts:IS_ANDROID_CHROME: truedoes not dispatchCONTROLLED_TEXT_INSERTION_COMMAND.CONTROLLED_TEXT_INSERTION_COMMAND(guard doesn't leak to other conditions).restartInputgracefully).