Skip to content

Bug: Tab + Korean IME composition freezes the editor in Safari (dev + prod) #8596

Closed

Description

@mayrang

Lexical version: 0.45 (latest main fd2e1856c)

Found while manual-testing #8594. The Korean IME path looks like it has been broken since the TabNode.setTextContent invariant was added, but it's not in any of the existing reports I could find — probably a long-standing edge case.

Steps To Reproduce

  1. Open https://playground.lexical.dev in Safari on macOS.
  2. Type foo.
  3. Press Tab.
  4. Start typing Korean (e.g. ㅁ).
2026-05-30.11.34.14.mov

Reproduces on:

  • macOS Safari (verified 26.3.1).
  • Deployed playground.lexical.dev and a local vite build + vite preview of lexical-playground (production build).
  • Local vite dev (development build).
  • All Lexical revisions tested via bisect, including a 2025-02 baseline.

Does not reproduce in Chromium with the same Korean IME.

Link to code example: playground.lexical.dev (default configuration).

The current behavior

The editor freezes: composition stays stuck, Backspace and Enter stop responding, English input doesn't recover the editor. Esc partially restores it (English works again), clicking outside and back partially restores Enter; only a hard refresh is a full recovery.

What I observed in DevTools:

After Tab + the first Korean key, Safari's MutationObserver delivers a text change on the TabNode's \t text node — composition targets the <span>\t</span> and Safari writes the new character into the existing text node (\tㅁ).

flushMutations translates that into TabNode.setTextContent('\tㅁ'). The current setTextContent throws (devInvariant against '\t' / ''). The throw goes through onError and breaks the active update; subsequent input / selection / composition events keep re-entering the same broken path:

Error: TabNode does not support setTextContent
  flushMutations
Error: $getTextNodeOffset: invalid offset 2 for size 1 at key 5
  onCompositionStart
  onInput
  onSelectionChange

In the dev bundle the readable message shows. In a local vite build of the playground the minified prod bundle still throws — the call site bundles to a function(t){throw new Error(t)} rather than a warn-only formatter. Whatever transformErrorMessages rewrite the Lexical npm release uses for devInvariant doesn't reach this build, so the throw still cascades end-to-end.

Existing context:

The expected behavior

Tab followed by Korean IME composition should behave the same as in Chromium: the Tab character stays in the document as a TabNode, IME composition completes on a new TextNode next to it, and the editor remains responsive.

Making TabNode.setTextContent accept any input and silently normalize to '\t' clears the cascade in both dev and prod for me:

setTextContent(_text: string): this {
  return super.setTextContent('\t');
}

After the change: Korean composition completes, Backspace removes the TabNode, Enter inserts a paragraph, English typing resumes, copy/paste preserves \t, Markdown shortcuts still fire.

A follow-up PR with a unit test that simulates the MutationObserver-driven setTextContent('\tX') call would keep the regression out. If the throw should stay (e.g. a different flushMutations hook strips the foreign text before reaching setTextContent), point at the better shape and I'll move that direction.

Impact of fix

  • Severity: editor unrecoverably frozen after a common keystroke sequence; requires a hard refresh.
  • Affects any Lexical-based editor that enables TabIndentationExtension (or otherwise inserts TabNode) and is used by Korean / Japanese / similar IME users on Safari. CJK-language adoption surface area.
  • Fix is one line plus a unit test.

Activity

  1. etrepum commented on May 30, 2026

    @etrepum
    Collaborator

    Are you sure that this doesn't create a different class of bug where the additional text is just lost?

  2. mayrang commented on May 30, 2026

    @mayrang
    CollaboratorAuthor

    When filing the issue I tried the normalize-to-\t approach locally and exercised the same Tab + Korean composition path, plus a few neighboring cases (Backspace removing the TabNode, Enter, English typing, copy/paste). Nothing visibly went missing in the editor state. To check that more directly I attached a MutationObserver on the contenteditable and ran foo + Tab + 안녕하세요:

    [CHILD] P + SPAN: "\t"          // TabNode added
    [CHAR] "\t" → "\t "             // Safari injects a space onto the TabNode text
    [CHAR] "\t " → "\tㅇ "           // Safari writes the first Korean jamo onto the TabNode text
    [CHAR] "\tㅇ " → "\t"            // setTextContent('\tㅇ ') hits, normalize-to-\t runs
    [CHILD] P + SPAN: "ㅇ "          // a sibling SPAN is created next to the TabNode
    [CHAR] "ㅇ " → "아 " → "안 " → ...  // composition continues on the sibling span until 안녕하세요
    

    Tree view after the repro:

    root
      └ paragraph
        ├ text "foo"
        ├ tab "\t"
        └ text "안녕하세요"
    

    The Korean character lands on a new sibling text node — the input / CONTROLLED_TEXT_INSERTION path picks it up after the normalize. I haven't traced down to the exact handler that creates the sibling, but the sibling-text-node result is reproducible across a few different first jamos and longer compositions.

  3. added a commit that references this issue on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions