Bug: Japanese IME composition data partially lost when composing immediately after a token-mode TextNode (e.g. EmojiNode)
Observed while investigating #5026 (which doesn't reproduce on a recent build).
Lexical version: current main (~0.44). Same observation on a v0.41.0 checkout.
Steps To Reproduce
- Open https://playground.lexical.dev/ in macOS Chrome
- Switch keyboard to Japanese - Romaji (macOS)
- In an empty paragraph, type
:)to create an EmojiNode 🙂 - With caret immediately after the emoji, press
tfour times
Link to code example: https://playground.lexical.dev/
The current behavior
The editor visibly shows 🙂t after the first t keypress and never updates again. Pressing t three more times produces no visible change — the caret stays put, no Japanese conversion (っ, っっ, っっっ) shows up. The user-visible result is 🙂t regardless of how many times t was pressed.
Internally, the events do fire — compositionupdate.data progresses through t → っt → っっt → っっっt — but none of the updates past the first one are reflected in the DOM. compositionend.data arrives as "🙂t" (the emoji content plus a t) rather than the IME's composed っっっt.
Final DOM: <span class="emoji">🙂</span><span data-lexical-text="true">t</span>. The emoji is preserved as a separate node, the t lands next to it, but everything the IME composed on top of that first t is gone.
Same reproduction in macOS Safari behaves correctly — the IME visibly progresses through t → っt → っっt → っっっt and commits the composed string.
Event log (Chrome, DevTools console)
keydown t
compositionstart ""
compositionupdate "t"
beforeinput insertCompositionText "t"
keydown t [comp]
compositionupdate "っt"
beforeinput insertCompositionText "っt"
keydown t [comp]
compositionupdate "っっt"
beforeinput insertCompositionText "っっt"
keydown t [comp]
compositionupdate "っっっt"
beforeinput insertCompositionText "っっっt"
compositionend "🙂t" ← emoji leaks in, っっっ never made it to the DOM
The expected behavior
Japanese IME composition next to an EmojiNode should visibly progress through t → っt → っっt → っっっt and commit the composed string on compositionend. The final paragraph should contain the emoji followed by the composed Japanese text — same as what Safari already does.
Impact of fix
Affects Lexical users typing Japanese (and likely other CJK IMEs that rely on browser composition events) immediately after a token-mode TextNode on Chromium-based browsers. Most prominently EmojiNode in the playground, but any custom token-mode TextNode behaves the same way. The user can't compose Japanese characters adjacent to an emoji; the IME's conversion is silently swallowed. Hit rate scales with how often the editor's content has token-mode TextNodes at line/paragraph edges. Safari users are unaffected.
Notes
The IME appears to misidentify the emoji span as the composition target (visible from the emoji content showing up in compositionend.data). Lexical already has a defensive \u200b (zero-width space) insertion in $handleCompositionStart that's intended to give the IME a safe sibling text node to compose into instead of letting it touch immutable spans. The current trigger conditions are:
- A recent keydown (Android composition latency)
anchor.type === 'element'- non-collapsed selection
- format / style mismatch between selection and node
None of those match when the caret sits at the trailing edge of a token-mode TextNode (text-anchored, collapsed, no mismatch). So the sentinel insertion doesn't fire and the IME ends up targeting the token's span. WebKit (Safari) handles the same DOM shape correctly, so the gap is Blink-specific — consistent with Lexical's existing browser-engine split for COMPOSITION_SUFFIX / COMPOSITION_START_CHAR.
A natural fix direction is to extend the heuristic with a "caret is at a token-mode TextNode boundary" condition (probably Chromium-gated to avoid regressing Safari, which is already correct). The compositionend data sanitization (stripping the leaked emoji content) would be a complementary cleanup.
Environment
- macOS Chrome 148 (Blink) — bug reproduces
- macOS Safari (current, WebKit) — works correctly
- Japanese - Romaji keyboard (macOS built-in)
Quick follow-up — after multiple attempts I couldn't reproduce this consistently on macOS Chrome 148; most sessions show correct behavior. Looks like a timing / IME-state-dependent flake rather than a deterministic bug.
For future reference if a reliable repro surfaces: $handleCompositionStart's heuristic doesn't currently cover the "caret at a token-mode TextNode boundary" case — the existing conditions (Android timing, element-anchored, non-collapsed, format/style mismatch) all miss text-anchored selections at the edge of a token. Could be worth a defensive sentinel-insertion patch there, but without a consistent repro I don't have a way to verify it actually helps.
Closing for now.