Skip to content

[lexical] Bug Fix: In the Safari browser, during the compositing event process, the delete key exhibits unexpected behavior. - #7061

Merged
etrepum merged 9 commits into
meta:mainfrom
BowenTew:fix/safari-start-composition
Jan 18, 2025
Merged

etrepum merged 9 commits into
meta:mainfrom
BowenTew:fix/safari-start-composition

Conversation

@BowenTew

Copy link
Copy Markdown
Contributor

Description

Fix the issue on the Safari platform where Lexical triggers compositionend before keydown, resulting in an extra character being deleted.

Closes ##6370

Test plan

Before

  1. Input Some Text, and then use a different language input, such as Chinese, trigger the composition event, and don't select word or press such as enter key
  2. press backslash, when delete the first composition character, it will delete both the start composition character and the character before the first composition character
345735748-59ab70e6-0075-411b-922e-5371f667143f.mp4

After

  1. only delete the beginning composition character
20250117-202950.mp4

@vercel

vercel Bot commented Jan 17, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 0:40am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 0:40am

@facebook-github-bot

Copy link
Copy Markdown
Contributor

Hi @EruditionTu!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions

github-actions Bot commented Jan 17, 2025 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
lexical - cjs 29.07 KB (+0.13% 🔺)
lexical - esm 28.89 KB (+0.1% 🔺)
@lexical/rich-text - cjs 38.04 KB (+0.21% 🔺)
@lexical/rich-text - esm 30.98 KB (+0.19% 🔺)
@lexical/plain-text - cjs 36.57 KB (+0.14% 🔺)
@lexical/plain-text - esm 28.26 KB (+0.47% 🔺)
@lexical/react - cjs 39.84 KB (+0.14% 🔺)
@lexical/react - esm 32.34 KB (+0.19% 🔺)

@facebook-github-bot facebook-github-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 Jan 17, 2025

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can reproduce this bug in macOS Safari and confirm that this fixes it. I can not reproduce the bug in macOS Firefox or Chrome before this PR, and this PR did not cause any regressions on any of those platforms in my testing.

All of this state in here makes me think we should have a real FSM driving all of these input behaviors across several events, rather than just a jumble of module global variables.

Thank you for the clear video showing how to reproduce the bug, and the fix!

@etrepum
etrepum added this pull request to the merge queue Jan 18, 2025
Merged via the queue into meta:main with commit 46c9c2f Jan 18, 2025
@BowenTew

Copy link
Copy Markdown
Contributor Author

Yes, in the subsequent iterations of Lexical, more elegant compatibility handling for input events across various browser platforms is needed, rather than applying patches in this manner. Looking forward to a better Lexical.

GermanJablo added a commit to GermanJablo/lexical that referenced this pull request Jan 30, 2025
commit a62a1a6
Author: James Fitzsimmons <[email protected]>
Date:   Thu Jan 30 19:13:35 2025 +1100

    [lexical-mark] Feature: include inline decorator nodes in marks (meta#7086)

commit 881c7fe
Author: Bob Ippolito <[email protected]>
Date:   Thu Jan 30 00:13:00 2025 -0800

    [lexical-utils] Fix: Modify $reverseDfs to be a right-to-left variant of $dfs (meta#7112)

commit ce2bb45
Author: Nigel Gutzmann <[email protected]>
Date:   Wed Jan 29 14:41:12 2025 -0800

    [lexical-utils] Feature: add reverse dfs iterator (meta#7107)

commit 3a140d2
Author: mohammed shaheer kp <[email protected]>
Date:   Tue Jan 28 06:19:45 2025 +0530

    [lexical-playground] Bug Fix: Ensure Delete Node handles all node types (meta#7096)

    Co-authored-by: shaheerkpzaigo <[email protected]>

commit 8e2ede2
Author: Adam Pugh <[email protected]>
Date:   Mon Jan 27 18:49:38 2025 -0600

    Listeners Lexical: 3 updates to spelling and grammar - Update listeners.md  (meta#7100)

commit 9fcc494
Author: Adam Pugh <[email protected]>
Date:   Mon Jan 27 18:49:34 2025 -0600

    Lexical Docs: 2 updates to spelling README.md (meta#7102)

commit 946a6df
Author: Adam Pugh <[email protected]>
Date:   Mon Jan 27 18:49:29 2025 -0600

    Selection | Lexical: 1 Spelling Update Update selection.md (meta#7103)

commit ce93ea6
Author: Adam Pugh <[email protected]>
Date:   Mon Jan 27 18:49:25 2025 -0600

    Creating a React Plugin: 1 Grammar Update - Update create_plugin.md (meta#7104)

commit ed29d89
Author: Adam Pugh <[email protected]>
Date:   Mon Jan 27 18:49:21 2025 -0600

    Working with DOM Events: 2 Spelling and Grammar Updates Update dom-ev… (meta#7105)

commit 212b70f
Author: James Fitzsimmons <[email protected]>
Date:   Mon Jan 27 08:48:09 2025 +1100

    [lexical-yjs] Bug Fix: handle text node being split by Yjs redo (meta#7098)

commit 6a98a47
Author: Torleif Berger <[email protected]>
Date:   Fri Jan 24 21:46:45 2025 +0100

    [lexical-react] Bug Fix: Import `JSX` type from React to prevent "Cannot find namespace 'JSX'"-error when type-checking with React 19 (meta#7080)

commit f8e5968
Author: Tetsuya <[email protected]>
Date:   Sat Jan 25 04:06:57 2025 +0800

    [lexical] Chore: Rename variable and add comments for Safari compositing workaround (meta#7092)

commit 81c9ab6
Author: Mateo Vuković <[email protected]>
Date:   Fri Jan 24 18:44:05 2025 +0100

    Fix: Use already defined RegisteredNodes type (meta#7085)

commit 63958a2
Author: Sherry <[email protected]>
Date:   Tue Jan 21 18:15:21 2025 +0800

    [playground] Bug fix: prevent growing whitespaces in markdown table toggle (meta#7041)

    Co-authored-by: Bob Ippolito <[email protected]>

commit d9f9924
Author: Sherry <[email protected]>
Date:   Tue Jan 21 14:58:08 2025 +0800

    Unrevert [Breaking Change][lexical] Bug Fix: Commit updates on editor.setRootElement(null) meta#7023 (meta#7068)

commit 92fa0a3
Author: mohammed shaheer kp <[email protected]>
Date:   Tue Jan 21 06:23:24 2025 +0530

    [lexical-playground] plugins TableOfContent Scroll smooth behaviour A… (meta#7069)

commit 2e4a63e
Author: Ivaylo Pavlov <[email protected]>
Date:   Mon Jan 20 02:37:34 2025 +0000

    [lexical-playground] Fix Columns Layout Item Overflow (meta#7066)

commit d319b07
Author: Bob Ippolito <[email protected]>
Date:   Sun Jan 19 14:45:41 2025 -0800

    Change fork modules to use production only when NODE_ENV explicitly set to production (meta#7065)

commit 46c9c2f
Author: CityHunter <[email protected]>
Date:   Sat Jan 18 13:00:38 2025 +0800

    [lexical] Bug Fix: In the Safari browser, during the compositing event process, the delete key exhibits unexpected behavior. (meta#7061)

    Co-authored-by: 涂博闻 <[email protected]>

commit 92a1cd7
Author: Violet Rosenzweig <[email protected]>
Date:   Thu Jan 16 18:44:11 2025 -0500

    docs: Change "here" link to more descriptive text (meta#7058)

commit f6377a3
Author: Aman Harwara <[email protected]>
Date:   Fri Jan 17 02:08:17 2025 +0530

    [lexical-table] Bug Fix: Prevent error if pasted table has empty row (meta#7057)

commit 0835029
Author: Aman Harwara <[email protected]>
Date:   Fri Jan 17 00:18:08 2025 +0530

    [lexical-list] Bug Fix: Prevent error when calling formatList when selection is at root (meta#6994)

commit 940435d
Author: Brayden <[email protected]>
Date:   Wed Jan 15 16:10:01 2025 -0800

    fix: iOS Autocorrect strips formatting by reporting wrong dataType (meta#5789)

    Co-authored-by: Bob Ippolito <[email protected]>

commit 136a565
Author: Aman Harwara <[email protected]>
Date:   Thu Jan 16 04:48:32 2025 +0530

    [lexical-yjs] Feature: Allow passing in custom `syncCursorPositions` function to collab hook (meta#7053)

commit 415c576
Author: Maksim Horbachevsky <[email protected]>
Date:   Wed Jan 15 18:18:03 2025 -0500

    fix: triple click around inline elements (links) (meta#7055)

commit a3ef4f3
Author: Ivaylo Pavlov <[email protected]>
Date:   Wed Jan 15 23:15:39 2025 +0000

    [lexical-table] Support table alignment (meta#7044)

commit 29d733c
Author: Sherry <[email protected]>
Date:   Wed Jan 15 21:50:07 2025 +0800

    Revert [Breaking Change][lexical] Bug Fix: Commit updates on editorSetRootElement(null) (meta#7023) (meta#7052)

commit 65ce66a
Author: Bob Ippolito <[email protected]>
Date:   Tue Jan 14 14:57:54 2025 -0800

    [lexical] Bug Fix: Normalize selection after applyDOMRange to account for Firefox differences (meta#7050)

commit bbc07af
Author: Bob Ippolito <[email protected]>
Date:   Tue Jan 14 08:55:46 2025 -0800

    [*] Bug Fix: Use GITHUB_OUTPUT instead of GITHUB_ENV for size-limit action (meta#7051)

commit c8f27ed
Author: Bob Ippolito <[email protected]>
Date:   Tue Jan 14 06:36:13 2025 -0800

    [Breaking Change][*] Chore: Use terser for optimizing cjs prod build (meta#7047)

commit 8bd22d5
Author: Bob Ippolito <[email protected]>
Date:   Mon Jan 13 07:09:31 2025 -0800

    [lexical] Bug Fix: Handle MutationObserver/input event re-ordering when using contentEditable inside of an iframe (meta#7045)

commit 930629c
Author: Ivaylo Pavlov <[email protected]>
Date:   Sat Jan 11 06:03:30 2025 +0000

    Clean up nested editor update (meta#7039)

commit bd874a3
Author: Bob Ippolito <[email protected]>
Date:   Fri Jan 10 15:23:54 2025 -0800

    [Breaking Change][lexical][lexical-selection][lexical-list] Bug Fix: Fix infinite loop when splitting invalid ListItemNode (meta#7037)

commit 541fa43
Author: Bob Ippolito <[email protected]>
Date:   Thu Jan 9 12:42:23 2025 -0800

    v0.23.1 (meta#7035)

    Co-authored-by: Lexical GitHub Actions Bot <>

commit d7abafd
Author: Bob Ippolito <[email protected]>
Date:   Thu Jan 9 08:33:12 2025 -0800

    [Breaking Change][lexical] Bug Fix: Commit updates on editor.setRootElement(null) (meta#7023)

commit 6add515
Author: Bob Ippolito <[email protected]>
Date:   Wed Jan 8 17:27:15 2025 -0800

    [lexical] Fix TabNode deserialization regression  (meta#7031)

commit 33e3677
Author: Maksim Horbachevsky <[email protected]>
Date:   Wed Jan 8 14:59:03 2025 -0500

    [lexical-react] Feature: Merge TabIndentionPlugin and ListMaxIndentLevelPlugin plugins (meta#7018)

commit 7de86e4
Author: James Fitzsimmons <[email protected]>
Date:   Wed Jan 8 09:45:25 2025 +1100

    [lexical-mark] Bug Fix: reverse ternary in MarkNode.addID (meta#7020)

commit 7961130
Author: Bob Ippolito <[email protected]>
Date:   Sun Jan 5 13:55:25 2025 -0800

    v0.23.0 (meta#7017)

    Co-authored-by: Lexical GitHub Actions Bot <>

commit 2b4252d
Author: Aman Harwara <[email protected]>
Date:   Sat Jan 4 11:31:19 2025 +0530

    [lexical-yjs] Feature: Expose function to get anchor and focus nodes for given user awareness state (meta#6942)

commit 8100d6d
Author: Ivaylo Pavlov <[email protected]>
Date:   Sat Jan 4 01:12:04 2025 +0000

    [lexical-playground] Fix table hover actions button position (meta#7011)

commit bd1ef2a
Author: Bob Ippolito <[email protected]>
Date:   Fri Jan 3 14:25:31 2025 -0800

    [lexical] Bug Fix: Fix registerNodeTransform regression introduced in meta#6894 (meta#7016)

commit 85c08b6
Author: Christian Grøngaard <[email protected]>
Date:   Thu Jan 2 00:20:20 2025 +0100

    [lexical-playground] Refactor: switch headings test file names (meta#7008)

commit 7c21d4f
Author: Bob Ippolito <[email protected]>
Date:   Wed Jan 1 12:48:12 2025 -0800

    [Breaking Change][lexical] Feature: Add updateFromJSON and move more textFormat/textStyle to ElementNode (meta#6970)

commit aaa9009
Author: Bob Ippolito <[email protected]>
Date:   Wed Jan 1 07:50:39 2025 -0800

    [lexical] Bug Fix: Fix getNodes over-selection (meta#7006)

commit 803391d
Author: Sherry <[email protected]>
Date:   Tue Dec 31 11:26:17 2024 +0800

    [__test__] npm upgrade astro (meta#7001)

commit 684352b
Author: Christian Grøngaard <[email protected]>
Date:   Mon Dec 30 05:12:45 2024 +0100

    Documentation: Fix typo "nest nest"->"nest" in README.md (meta#7000)

    Co-authored-by: Bob Ippolito <[email protected]>

commit 27b75cc
Author: Sherry <[email protected]>
Date:   Fri Dec 27 11:06:29 2024 +0800

    [__tests__] npm upgrade next (meta#6996)

commit 05ddbcc
Author: Simon <[email protected]>
Date:   Thu Dec 26 03:37:50 2024 +0100

    [lexical] Bug Fix: Flow is missing some variables and functions (meta#6977)

commit e79c946
Author: Sherry <[email protected]>
Date:   Tue Dec 24 09:54:46 2024 +0800

    v0.22.0 (meta#6993)

    Co-authored-by: Lexical GitHub Actions Bot <>

commit c415f7a
Author: Sam Zhou <[email protected]>
Date:   Mon Dec 23 10:31:36 2024 -0800

    [lexical-react] Refactor: Replace `React$MixedElement` and `React$Node` with `React.MixedElement` and `React.Node` (meta#6984)

commit c844a4d
Author: Sherry <[email protected]>
Date:   Tue Dec 24 02:30:52 2024 +0800

    [lexical] Fix flow error: change this to any (meta#6992)

commit 6190033
Author: Germán Jabloñski <[email protected]>
Date:   Mon Dec 23 05:19:27 2024 -0300

    Refactor: exportJSON (meta#6983)

commit e0dafb8
Author: Germán Jabloñski <[email protected]>
Date:   Sat Dec 21 13:59:01 2024 -0300

    feature: expose forEachSelectedTextNode (meta#6981)

    Co-authored-by: Bob Ippolito <[email protected]>

commit 23715f5
Author: Alex <[email protected]>
Date:   Fri Dec 20 18:23:27 2024 +0300

    [lexical][lexical-table] Bug fix: TablePlugin:  - check is current selection in target table node (meta#6979)

    Co-authored-by: alazarev <[email protected]>
justinchen13 added a commit to justinchen13/lexical that referenced this pull request Oct 17, 2026
…lled desktop WebKit compositions

## Description

With macOS system Pinyin in a desktop WKWebView, start after existing text (`abc`), type unconfirmed `ni`, then press Backspace twice or Escape. WebKit sends an empty DOM `compositionend` without `insertFromComposition`, but Lexical retains its composition key. The next ordinary Enter is dropped before `KEY_ENTER_COMMAND` can dispatch.

Finish empty desktop WebKit compositions immediately. Keep ignoring the trailing `keyCode=229` already consumed by the IME, preserving meta#7061's protection against extra body deletion; ordinary Backspace/Enter (`8`/`13`) work normally. Nonempty WebKit completion retains its deferred path. This system-Pinyin cancellation differs from the third-party Xunfei case in closed meta#8181.

Cancellation synchronizes current text and removes only a proven editor-owned placeholder. This requires tracking actual insertion and maintaining or invalidating its range through text edits, split/merge, JSON updates and active selection slices. The metadata belongs to the active node object: same-key ephemeral/export copies cannot change it, and editor-free copy edits remain supported. The text schema routes JSON writes through `setTextContent`; both affected generated updaters follow that schema. There is no old whole-node rollback or blanket NBSP removal; public APIs and node JSON format are unchanged.

The regressions enter through native DOM `compositionend` handlers, covering PlainText/RichText, trailing keys, real NBSP, empty roots, selection/format/type boundaries, model/JSON updates and live/copy isolation. The browser replays are synthetic. A separate system-Pinyin/HID capture validates the frozen implementation physically.

Reproduction sources, versioned failures, raw native records and exact commands are in the [commit-pinned evidence README](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/README.md), [source/build identity](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/source-manifest.json), and [content-hash index](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/evidence-index.json). Evidence lives on a separate fork branch; this PR contains only the ten source/test files.

## Test plan

### Before

Exact upstream baseline: `cb21da40de69c1eedc2b9ec60001fef0d3b1770a` (0.52.0). Historical run of the **original 58-case** regression file, before later JSON/copy cases were added:

```sh
VITEST_BROWSER=chromium pnpm run test-browser packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
```

Actual output, exit 1 ([log](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/logs/reviewed-final-regression.log)):

```text
 Test Files  1 failed (1)
      Tests  58 failed (58)
```

The [historical native dataset](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/historical-events-v2.jsonl)'s **before** variant used this exact unmodified upstream commit and reproduced six missing-Enter failures. It is reused as the baseline; its older after variant is not final-fix evidence. Additional intermediate-version failures are indexed in the README.

### After

The following existing checks apply to the identical final ten-file fingerprints; committing/publishing does not change those bytes.

```sh
MOZ_DISABLE_CONTENT_SANDBOX=1 VITEST_BROWSER=chromium,firefox,webkit pnpm run test-browser packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts packages/lexical/src/__tests__/browser/LexicalComposition.test.ts
```

Actual output, exit 0 ([log](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/logs/v4-browser.log)):

```text
 Test Files  6 passed (6)
      Tests  358 passed | 2 skipped (360)
```

```sh
pnpm run test-unit packages/lexical/src packages/lexical-code-core/src packages/lexical-selection/src packages/lexical-clipboard/src packages/lexical-html/src packages/lexical-markdown/src packages/lexical-yjs/src
```

Actual output, exit 0 ([log](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/logs/v4-unit.log)):

```text
 Test Files  142 passed (142)
      Tests  3524 passed (3524)
```

Source/test TypeScript (`pnpm run tsc`, `pnpm run tsc-test`), ESLint and Prettier on all ten changed files exited 0. [ESLint](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/logs/v4-lint-final.log) reported 0 errors and 1 naming warning for the test's `slice` callback (`@lexical/rules-of-lexical`); the frozen spelling is retained. Generator drift, schema parity and clone/serialization are covered by the unit run. The previous Flow full-check reported `Found 0 errors` (exit 0); its 152 definition/config/lock inputs are unchanged, so it was reused. [Quality scope and log references](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/quality-scope.json).

Final native capture: macOS 27.0.1 (26A434), arm64, system WKWebView/WebKit 22625.1.29.11.28; exact input source `com.apple.inputmethod.SCIM.ITABC`. The separate source fixture rebuild and evidence verification commands are:

```sh
node /path/to/ime-repro/build.mjs .
python3 /path/to/ime-repro/verify.py --checkout .
```

Actual verifier output, exit 0 ([log](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/logs/final-native-verify.log), [raw events](https://github.com/13Cohen/lexical/blob/357bb810499d05054e7f1dde397bad0c02070488/packages/lexical/ime-cancellation-evidence/events.jsonl)):

```text
Native final active-node-v4: 14/14 scenarios passed (6 PlainText, 8 RichText).
All 276 DOM input/composition/key events and 64 keydowns are trusted; no modifier shortcut was used.
Exact system Pinyin verified; previous input source and application/focus restored.
Historical exact-upstream baseline reused: 6 missing-Enter failures; no baseline rerun.
```

All 14 following ordinary Enter presses dispatched once; consumed `229` keys did not cause an extra command/deletion. Space confirmation committed “你”; Enter confirmation committed raw “ni”. Cancellation, real NBSP, cross-paragraph text, active JSON/slices and independent copies passed. Seven cases invoke programmatic model APIs after a trusted native compositionstart, then continue real OS input/cancellation; these are explicit API/IME interactions, not remote collaboration. All 134 build inputs matched and the post-capture bundle rebuild was byte-identical.

Physical coverage is limited to this system WKWebView/Pinyin setup. Standalone Safari/Chrome/Firefox, other OSes/IMEs, CodeHighlight/custom-node native matrices, no-input immediate cancellation and live remote Yjs were not physically exercised. The full monorepo/CI matrix, E2E and release/site builds were not repeated; older full-suite results are historical only. Detailed environment/tool versions and reuse boundaries are in the evidence README.
justinchen13 added a commit to justinchen13/lexical that referenced this pull request Oct 18, 2026
…eparation in input handling

## Description

Cancelling unconfirmed macOS system Pinyin with Backspace or Escape can leave desktop WebKit's composition key active. The next ordinary Enter then never reaches `KEY_ENTER_COMMAND`. Finish an empty DOM `compositionend` immediately, ignore trailing `keyCode=229` events already consumed by the IME, and preserve normal Backspace/Enter handling and meta#7061's confirmation behavior.

Prepare a DOM composition target without inserting `COMPOSITION_START_CHAR` into document text. Preserve an empty target through normalization and selection resolution, and select its existing rendered suffix for WebKit to replace. This removes the previously proposed TextNode ownership hooks, schema/generated-JSON changes, and cross-package slicing changes. TextNode and those implementations now match upstream.

## Test plan

### Before

The exact-base native cancellation failure is preserved in the historical evidence; it was not rerun. After ordinary Enter, the recorded command list was empty.

Published v4 implementation with the preparation regression:

```sh
VITEST_BROWSER=chromium,webkit pnpm run test-browser packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts -t 'composition prepares a DOM target'
```

```text
Tests  24 failed | 4 passed | 164 skipped (192)
Command failed with exit code 1.
```

The first DOM-target attempt exposed a formatted-target boundary during physical validation. Its corresponding new browser-range regression failed before the fix:

```sh
VITEST_BROWSER=chromium,webkit pnpm run test-browser packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts -t 'browser editing replaces the DOM suffix'
```

```text
Tests  4 failed | 240 skipped (244)
Command failed with exit code 1.
```

### After

Final DOM-range regression:

```text
Tests  4 passed | 240 skipped (244)
```

Current Safari-event regression file across Chromium/Firefox/WebKit:

```text
Test Files  3 passed (3)
Tests  366 passed (366)
```

Affected model/selection/editor/history unit tests:

```text
Test Files  12 passed (12)
Tests  327 passed (327)
```

The wider core/RichText browser scope has 2075 passing tests and 8 skips by combining 81 unchanged engine-files with 3 current file runs. The earlier broad invocation initially failed only two Firefox assertions because `Selection.toString()` normalizes NBSP; the corrected test reads raw Range text. This combined scope is distinguished from a fresh passing broad invocation in the evidence.

Source/test TypeScript, strict seven-file lint (0 errors/0 warnings), and formatting exited 0. Generator/JSON/slice checks from the earlier 716-test run are reused for unchanged implementations; Flow's prior successful result is reused for unchanged inputs.

Final physical system-IME capture: 20/20 scenarios, 397 trusted DOM events and 91 trusted keydowns, exact `com.apple.inputmethod.SCIM.ITABC`, modifier-free HID input, system WKWebView on macOS 27.0.1 / WebKit 22625.1.29.11.28. It covers cancellation, confirmation, ordinary 8/13, consumed 229, NBSP, empty/formatted/token targets, selections, JSON/live slices/copies and subclass boundaries. Space committed `你`; Enter committed raw `ni`. All 134 build inputs matched and rebuilding reproduced the captured bundle byte-for-byte. Input source and focus were restored; exit 0.

Browser composition replays are synthetic and are not counted as physical IME evidence. No new full monorepo unit run, E2E, full ci-check, release build, other physical OS/IME, or standalone Safari/Chrome capture was performed. Detailed methods, version identities and immutable records are in the source-only reproduction bundle prepared for PR meta#9362.

The project pre-commit hook is enabled. This follows the maintainer's agreement that IME handling should happen on input rather than in the model.

This branch was successfully deployed

2 active deployments
Preview – lexical — 77ae1c6a Deployed Jan 17, 2025 by vercel[bot]
Preview – lexical-playground — 77ae1c6a Deployed Jan 17, 2025 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.

3 participants