Skip to content

[lexical] Bug Fix: TabNode.setTextContent for Safari IME composition - #8598

Merged
etrepum merged 1 commit into
meta:mainfrom
mayrang:fix/8596-tab-ime-safari
May 30, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
mayrang:fix/8596-tab-ime-safari

Conversation

@mayrang

@mayrang mayrang commented May 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Closes #8596.

In Safari, the MutationObserver delivers mid-IME-composition text writes straight onto the TabNode's \t text node — IMEs that compose onto the existing text node (verified with Korean) cause Safari to rewrite it to e.g. \tㅁ. flushMutations then calls TabNode.setTextContent('\tㅁ'), the current devInvariant throws, and the throw cascades through onError: composition stays stuck, Backspace / Enter / English input all stop responding until a hard refresh.

The throw has existed since TabNode was introduced. The only earlier hit on it was selection-based typing across the node, which #7602 already covered by treating TabNode as token-mode. The MutationObserver / IME path is a separate route into the same method and was uncovered.

Drop the devInvariant check entirely. The body already normalizes to \t via super.setTextContent('\t'), so removing the check changes nothing about the stored content — the reconciler still renders the canonical \t on the next update. The dropped check was guarding caller assumptions, not stored state.

A few notes for reviewers:

  • Only setTextContent sits on the Safari MutationObserver path. spliceText is gated by the $isTabNode(firstNode) early-return in LexicalSelection.ts; setDetail / setMode aren't on any IME-triggered path. Those invariants stay.
  • packages/lexical-yjs/src/CollabTextNode.ts calls setTextContent(collabText) on synced text nodes, including a TabNode whose remote text might be non-\t. The dev throw previously surfaced that drift in dev; in prod it was already a warn-only path. After this change dev matches prod's behavior — silently normalize to \t. Not a new prod regression.

Test plan

  • pnpm tsc --noEmit -p tsconfig.json — clean
  • pnpm flow — clean
  • prettier + eslint clean on changed files
  • pnpm vitest run --project unit -t "LexicalTabNode tests" — 18 passed (new test added: setTextContent normalizes back to \t without throwing (#8596) covering the setTextContent('\tㅁ') shape flushMutations produces, plus an arbitrary string and '')
  • Manual: Safari (macOS 26.3.1) on local vite build + vite preview of lexical-playground — foo + Tab + Korean composition now completes; Backspace removes the TabNode, Enter inserts a paragraph, English typing resumes, copy/paste preserves \t, Markdown shortcuts still fire.
  • Manual: Chromium parity — same flows behave identically (no regression from removing the check on the non-Safari path).
  • Manual: confirmed no text loss via a MutationObserver on the contenteditable. After foo + Tab + Korean composition, Safari writes the in-flight jamo onto the TabNode's \t text node and the normalize fires; the Korean character then lands on a sibling TextNode (input / CONTROLLED_TEXT_INSERTION path) and composition continues there. Final editor state: paragraph[text "foo", tab "\t", text "안녕하세요"] — Korean preserved.

@vercel

vercel Bot commented May 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment May 30, 2026 4:29pm
lexical-playground Ready Ready Preview, Comment May 30, 2026 4:29pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 30, 2026
@mayrang mayrang changed the title [lexical] Bug Fix: TabNode.setTextContent for Safari IME composition (#8596) [lexical] Bug Fix: TabNode.setTextContent for Safari IME composition May 30, 2026
…or Safari IME compat (meta#8596)

In Safari, the MutationObserver delivers mid-IME-composition text writes straight onto the `TabNode`'s `\t` text node — Korean / Japanese / similar IMEs compose onto the existing text node, and Safari rewrites it to `\tㅁ`. `flushMutations` then calls `TabNode.setTextContent('\tㅁ')`, the `devInvariant` throws, and the throw cascades through `onError`, freezing the editor (composition, Backspace, Enter, English input all stop working until a hard refresh).

The throw existed since `TabNode` was introduced, but the only path that surfaced it before was selection-based typing across the node (fixed by treating the node as token-mode in meta#7602). The MutationObserver / IME path was uncovered.

Drop the `devInvariant` check entirely. The body already normalizes to `\t` via `super.setTextContent('\t')`, so the throw never carried information the reconciler couldn't recover from — the next update re-renders the canonical `\t`. A unit test exercises the exact `setTextContent('\tㅁ')` shape `flushMutations` produces so the regression doesn't return.
@etrepum
etrepum added this pull request to the merge queue May 30, 2026
Merged via the queue into meta:main with commit 150bf8a May 30, 2026
35 checks passed
etrepum pushed a commit to etrepum/lexical that referenced this pull request May 30, 2026
Picks up meta#8593 (linear-time regexes / prototype-pollution guards /
faster CSS parsing) and meta#8598 (TabNode.setTextContent Safari IME
fix) — both touch lexical/extension/markdown/playground/yjs and
don't intersect with the release tooling on this branch, so the
merge is clean.

https://claude.ai/code/session_01UEAeW4ZkfApZnrJTGc6Xm9

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

LGTM ✅ — Important Safari IME crash fix in TabNode.

What this does: Fixes #8596 where Safari's MutationObserver delivers mid-IME-composition text (e.g. Korean characters) onto the TabNode's \t text node. Previously, setTextContent would throw a devInvariant error if the text wasn't '\t' or '', which cascaded through onError and froze the editor. The fix changes the method to always normalize content back to '\t' regardless of input, ignoring any IME composition payload.

What I checked:

  • ✅ Logic correctness: The approach is sound — TabNode's content is canonical (\t), so any input should be normalized rather than rejected. The reconciler will render the canonical content on the next update, overwriting the DOM mutation that triggered this. The devInvariant was overly strict for a scenario the original author didn't anticipate (browser-initiated mutations via MutationObserver during IME).
  • ✅ Behavioral change is safe: The old behavior was THROWING on unexpected input. The new behavior is NORMALIZING. Callers that previously got an error now get silent normalization — strictly better UX.
  • ✅ devInvariant → super.setTextContent('\t'): Always writes \t regardless of input. The _text parameter is intentionally ignored (underscore prefix convention).
  • ✅ Test coverage: New test verifies setTextContent with various inputs ('\tㅁ', 'arbitrary', '') never throws and always normalizes to \t.
  • ✅ www compat: This is an internal behavioral fix in a core Lexical node. The change makes TabNode MORE robust — any www code that was previously hitting this invariant (Safari + Korean/CJK IME users) will now work correctly.
  • ✅ CI: All checks green.

Safe to land. Critical UX fix for Safari IME users — editor freeze is unacceptable for a text editing library.

@etrepum etrepum mentioned this pull request Jun 25, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 173a9140 Deployed May 30, 2026 by vercel[bot]
Preview – lexical-playground — 173a9140 Deployed May 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants