Repository navigation
[lexical] Bug Fix: Finish cancelled desktop WebKit compositions - #9362
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @13Cohen! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
## Description
Rename the Safari composition regression's local slice callback to $slice and
update its two references. This satisfies rules-of-lexical without changing
any test setup, assertion, production source or native build input.
All eight business-source fingerprints and all 134 inputs of the recorded
14-case system-Pinyin/WKWebView capture still match. The captured manifests
remain historical originals; regression results and native evidence are reused.
## Test plan
### Before
```sh
pnpm exec eslint --max-warnings 0 packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
```
Actual output (exit 1):
```
389:11 warning $getRoot called from slice, without $ prefix or read/update context @lexical/rules-of-lexical
✖ 1 problem (0 errors, 1 warning)
0 errors and 1 warning potentially fixable with the `--fix` option.
ESLint found too many warnings (maximum: 0).
```
### After
```sh
pnpm exec eslint --max-warnings 0 --format json packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
pnpm exec prettier --check packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
```
ESLint exited 0. Actual JSON fields:
```json
{"errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}
```
Actual Prettier output (exit 0):
```
Checking formatting...
All matched files use Prettier code style!
```
The original 358 browser passes / 2 skips and 3524 unit passes remain applicable
to this pure callback rename. No physical IME run or full suite was repeated;
standalone browsers, other OSes/IMEs and remote Yjs remain outside physical
coverage. The project pre-commit hook is enabled for this follow-up commit.
901bc60 to
b77e004
Compare
etrepum
left a comment
There was a problem hiding this comment.
I don’t think that this is the best approach, IME related code doesn’t belong in TextNode
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Agreed, the new IME tracking doesn’t belong in TextNode. I’m thinking of keeping this in the input handling: prepare the DOM composition target without adding a placeholder to the document model, keep it alive during composition, and finish an empty compositionend immediately. That would remove the TextNode hooks and related JSON/slicing changes. Any concerns with that direction? If it looks reasonable, I’ll try updating this PR with it and verify it with the system IME. |
|
Yes, IME handling should happen on input not as part of the model. |
…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.
## Description Publish source-only reproduction material for the revised input-layer fix in meta#9362, source commit 77c26a9. The previous active-node-v4 records remain historical. The new index includes the 20-case trusted system-Pinyin capture, raw failure/pass logs, reproduction sources, immutable capture identities and the committed-source correspondence. Only this evidence branch receives these files; the code PR remains seven files. ## Test plan ### Before Published v4 with the new preparation regression (synthetic browser events): ```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. ``` ### After ```sh node /path/to/lexical-ime-repro-dom-target-v2/verify.mjs /path/to/checkout ``` Actual output, exit 0, including verification after a fresh ZIP extraction: ```text Native records: 20/20 scenarios, 397/397 trusted DOM events, 91/91 trusted keydowns; ordinary 8/13 and consumed 229 checks passed. Current code: all 134 capture inputs and 7 changed files match; rebuilt native bundle is byte-identical to capture. Working-tree HEAD metadata may differ in a fresh checkout. Capture manifests are immutable; file and bundle bytes define the tested implementation. ``` Public paths, credentials and internal references were scanned. Sources and records are included; compiled runtime bundles and native executables are not. The capture is macOS system WKWebView with SCIM.ITABC; other physical platforms, standalone browsers, remote Yjs and a fresh full monorepo run remain untested.
etrepum
left a comment
There was a problem hiding this comment.
This looks directionally correct but seems to add more code than is necessary (in the implementation and in tests). Here's a more detailed review from claude:
The cancellation fix looks right: ending an empty compositionend immediately and ignoring desktop WebKit's trailing keyCode === 229 keydown is the natural fix for the stuck composition key. A few changes before this lands:
-
Remove the
ending-safariphase. Now that 229 keydowns return early inonKeyDown,$handleKeyDownnever sees one on desktop WebKit, soisBackspace(event) && event.keyCode === 229can't be true. The branch only resets the phase on the next ordinary key. Confirmed compositions are finished byinsertFromComposition, and cancellations now end at once, so the phase,compositionEndDataand the #7061 branch can all go. With them removed, all ofLexicalSafariComposition.test.tsstill passes. -
The placeholder redesign is heavier than the problem. As far as I can tell, the cancel path only needs it because
$updateTextNodeFromDOMContentstrips everyCOMPOSITION_START_CHAR(NBSP on WebKit) at composition end, which would drop real NBSPs. Could that loop strip only the placeholder Lexical inserted (track its node key and offset in_inputState) instead? That would avoid theisPreparingCompositionflag, the empty-target exemptions in normalization and selection resolution, the selected-suffix DOM range, and the trailing-NBSP heuristic. This path runs for every desktop Safari IME start, including typing into an empty paragraph, and only Pinyin was checked on a real IME. If the redesign does need to stay, please put the special case in$handleCompositionStart(remove the placeholder from the target right after the dispatch) rather than a flag that changes whatinsertTextinserts. -
Trim the tests. 872 lines is a lot to review. The Backspace/Escape cancellation cases, the confirmation case, and the real-NBSP cases cover the fix, and the
set/splice/jsonand other matrices could go. Please also assert througheditor.isComposing()rather thaneditor._compositionKey. -
If possible, a quick manual check with the Japanese and Korean IMEs in Safari, since the composition start path is shared by all of them.
diff --git a/packages/lexical/src/LexicalEditor.ts b/packages/lexical/src/LexicalEditor.ts
index 6ad5f2d..6bfeb94 100644
--- a/packages/lexical/src/LexicalEditor.ts
+++ b/packages/lexical/src/LexicalEditor.ts
@@ -274,8 +274,7 @@ export interface CollapsedSelectionFormat {
/** @internal */
export interface InputState {
- compositionPhase: 'idle' | 'composing' | 'ending-firefox' | 'ending-safari';
- compositionEndData: string;
+ compositionPhase: 'idle' | 'composing' | 'ending-firefox';
isPreparingComposition: boolean;
/**
* The segmented node that insertText switched to normal mode to compose
@@ -343,7 +342,6 @@ export function createInputState(): InputState {
timeStamp: 0,
},
composedSegmentedKey: null,
- compositionEndData: '',
compositionPhase: 'idle',
hadOrphanedCompositionEvents: false,
handledSelectionCommandTimeoutId: null,
diff --git a/packages/lexical/src/LexicalEvents.ts b/packages/lexical/src/LexicalEvents.ts
index 4c71fe6..d8f9341 100644
--- a/packages/lexical/src/LexicalEvents.ts
+++ b/packages/lexical/src/LexicalEvents.ts
@@ -150,7 +150,6 @@ import {
getNearestEditorFromDOMNode,
getParentElement,
getWindow,
- isBackspace,
isDOMCapturingSelection,
isDOMDocumentNode,
isDOMNode,
@@ -1984,13 +1983,10 @@ function onCompositionEnd(
const inputState = editor._inputState;
if (IS_FIREFOX) {
inputState.compositionPhase = 'ending-firefox';
- } else if (event.data !== '' && !IS_IOS && (IS_SAFARI || IS_APPLE_WEBKIT)) {
- // https://github.com/facebook/lexical/pull/7061
- inputState.compositionPhase = 'ending-safari';
- inputState.compositionEndData = event.data;
- } else {
- // Cancellation has no insertFromComposition event to finish the Safari
- // composition. Release it now so the next ordinary key can dispatch.
+ } else if (event.data === '' || IS_IOS || !(IS_SAFARI || IS_APPLE_WEBKIT)) {
+ // Desktop WebKit finishes a confirmed composition with
+ // insertFromComposition. Cancellation has no such event, so release it
+ // now so the next ordinary key can dispatch.
dispatchCommand(editor, COMPOSITION_END_COMMAND, event);
}
}
@@ -2198,20 +2194,6 @@ function $handleKeyDown(event: KeyboardEvent): boolean {
if (event.key == null) {
return true;
}
- if (inputState.compositionPhase === 'ending-safari') {
- const isBack = isBackspace(event) && event.keyCode === 229;
- if (isBack) {
- updateEditorSync(editor, () => {
- $onCompositionEndImpl(editor, inputState.compositionEndData);
- });
- }
- inputState.compositionPhase = 'idle';
- inputState.compositionEndData = '';
- if (isBack) {
- return true;
- }
- }
-
let keyDownShortcuts = editor._keyDownShortcuts;
if (keyDownShortcuts === null) {
keyDownShortcuts = compileKeyboardShortcuts(buildKeyDownShortcuts());…ut inserting document text ## Description Composition preparation currently sends an NBSP through the controlled text insertion command and uses an editor-global flag to suppress it in insertText. Application handlers using insertRawText or insertNodes bypass that suppression and retain the NBSP after cancellation. Cancelling a prepared formatted target also adds an Undo step even though the document has not changed. Share the selection insertion routing with an internal composition-target helper, keeping preparation out of application text insertion handlers and preserving ordinary insertText semantics. Remove the preparation flag and the unreachable ending-safari phase; successful insertFromComposition resets the input phase directly. Keep the empty-target normalization and selected DOM suffix protections that native WebKit requires. At composition end, merge an unchanged serialized document into the current history entry without advancing the typing boundary. Include formatting, structure and NodeState in that comparison, and retain explicit history pushes. Reduce obsolete model-mutation test matrices and use public composition state assertions. Cover application insertion handlers, cancellation, selected-text replacement, genuine NBSP, confirmation, and undo of meaningful document changes. ## Test plan ### Before On unmodified PR head 77c26a9, with the final regression file: ```sh PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1 VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts ``` Actual output, exit 1: ```text Test Files 1 failed (1) Tests 14 failed | 60 passed (74) ``` ### After The same command exits 0: ```text Test Files 1 passed (1) Tests 74 passed (74) ``` Broad core and RichText browser scopes: ```sh PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1 VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser packages/lexical-rich-text/src/__tests__/browser ``` Actual output, exit 0: ```text Test Files 28 passed (28) Tests 647 passed | 2 skipped (649) ``` Chromium used a local configuration selecting /usr/bin/chromium. Actual output, exit 0: ```text Test Files 28 passed (28) Tests 644 passed | 1 skipped (645) ``` ```sh node node_modules/vitest/vitest.mjs --project unit --project scripts-unit --no-watch packages/lexical/src packages/lexical-history/src packages/lexical-selection/src packages/lexical-code-core/src packages/lexical-yjs/src ``` Actual output, exit 0: ```text Test Files 119 passed (119) Tests 2752 passed (2752) ``` Source and test TypeScript, strict five-file ESLint and Prettier checks exited 0. The pre-commit hook runs the repository's formatter and linter on staged files. These browser tests run real Linux WebKit/Chromium with synthetic composition events. No physical macOS Pinyin/Japanese/Korean IME capture, full E2E/release build, or external CI rerun was performed. Tests use the saved dependency tree: Node 24.21.0, Vitest 5.0.0, Playwright 1.62.1, WebKit 26.5.
…ation before history
## Description
Remove the full-document JSON comparison from history. Track the empty target
created for a collapsed desktop WebKit composition in core. Document commits
invalidate the preparation marker; selection-only commits preserve it.
Cancellation adds HISTORY_MERGE_TAG only while that target remains untouched
and empty after reading native DOM text. History uses its existing merge-tag
handling, including explicit push precedence and editor identity checks.
Selected-text deletion and intervening formatting, NodeState, and indentation
changes retain their undo boundaries. Browser regressions prohibit EditorState
serialization and cover native text surviving an empty compositionend payload.
## Test plan
### Before
With the previous history implementation and the no-serialization assertion:
VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts -t 'cancelling a formatted target does not add'
Test Files 1 failed (1)
Tests 2 failed | 72 skipped (74)
### After
VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
Test Files 1 passed (1)
Tests 76 passed (76)
VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser packages/lexical-rich-text/src/__tests__/browser
Test Files 28 passed (28)
Tests 647 passed | 2 skipped (649)
node node_modules/vitest/vitest.mjs --project unit --project scripts-unit --no-watch packages/lexical/src packages/lexical-history/src packages/lexical-selection/src
Test Files 104 passed (104)
Tests 2554 passed (2554)
Source TypeScript and strict ESLint pass. Broad WebKit ran before the additional
native-DOM empty-target guard; the final targeted run covers that guard.
WebKit ran with locally supplied libraries and host validation disabled.
Browser events are synthetic replays in real WebKit; physical macOS IME
validation and external CI were not run. Cached dependencies differ from the
lockfile; no dependency installation or lockfile changes were made.
…ink][lexical-markdown][lexical-playground][lexical-react][lexical-rich-text][lexical-utils][lexical-website] Chore: Merge main into composition fixes ## Description Merge main at 5e46754 into the composition fix branch. Resolve the LexicalEvents import conflict by retaining both the composition-preparation helper and the new slot-frame helper. ## Test plan ### Before git merge --no-ff --no-commit origin/main CONFLICT (content): Merge conflict in packages/lexical/src/LexicalEvents.ts Automatic merge failed; fix conflicts and then commit the result. ### After git diff --cached --name-only --diff-filter=U (no output) VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser packages/lexical-rich-text/src/__tests__/browser Test Files 2 failed | 28 passed (30) Tests 2 failed | 696 passed | 2 skipped (700) The two browser failures and two unit failures below were timeouts during concurrent test/typecheck runs. Their files pass on isolated reruns. node node_modules/vitest/vitest.mjs --project unit --no-watch packages/lexical/src packages/lexical-history/src packages/lexical-selection/src Test Files 1 failed | 105 passed (106) Tests 2 failed | 2581 passed (2583) node node_modules/vitest/vitest.mjs --project unit --no-watch packages/lexical/src/__tests__/unit/LexicalSlot.test.ts Test Files 1 passed (1) Tests 124 passed (124) node node_modules/typescript/bin/tsc --noEmit (no output; exit 0) VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/Issue7158MouseDrag.test.ts packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionArrow.test.ts Test Files 2 passed (2) Tests 173 passed (173) WebKit uses cached browser binaries and locally supplied host libraries, with host-requirements validation disabled. No physical macOS IME validation or external CI was run. Installed dependencies differ from the lockfile; no dependency installation was performed.
…on out of undo history
## Description
Cancelling a prepared formatted composition target after inserting and deleting
composition text still added an empty undo step: the first document commit
invalidated the empty-target marker. Track all node keys dirtied during a
composition in history, then compare their exports and element child keys at
composition end. Unchanged node references and nodes absent from both states
need no export. This avoids serializing the full document while retaining undo
boundaries for selected-text deletion, formatting, NodeState, indentation, and
native text surviving an empty compositionend payload.
Remove compositionPreparationState, the core commit hook, and cancellation's
special merge tag. Preserve explicit history-push precedence, shared-editor
checks, and the preceding typing classification when composition is unchanged.
Clear collected keys at composition end and historic updates.
Add the typed-then-deleted cancellation replay in plain and rich text. Assert
that intermediate composition text reaches the model, disappears before the
end event, and one Undo reverses the preceding real edit. Retain the assertion
that EditorState.toJSON is never called.
## Test plan
### Before
VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
Test Files 1 failed (1)
Tests 2 failed | 76 passed (78)
The typed-then-cancelled cases left abcX after Undo instead of abc.
### After
VITEST_BROWSER=webkit node node_modules/vitest/vitest.mjs --project browser --no-watch packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts
Test Files 1 passed (1)
Tests 78 passed (78)
node node_modules/vitest/vitest.mjs --project unit --no-watch packages/lexical/src packages/lexical-history/src packages/lexical-selection/src
Test Files 106 passed (106)
Tests 2583 passed (2583)
node node_modules/typescript/bin/tsc --noEmit
(no output; exit 0)
Strict ESLint and Prettier checks pass for all five changed files.
WebKit uses cached binaries and local host libraries, with host-requirements
validation disabled. Events are synthetic replays in real WebKit; physical
macOS IME validation and external CI were not run. Cached dependencies differ
from the lockfile; no dependencies were installed or lockfiles modified by
this fix.
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/yjs
commit: |
Description
Cancelling unconfirmed macOS system Pinyin with Backspace or Escape can leave desktop WebKit composing, so the next ordinary Enter never reaches
KEY_ENTER_COMMAND. Finish an empty DOMcompositionendimmediately and ignore trailingkeyCode=229events already consumed by the IME. Ordinary Backspace/Enter still work; nonempty completion retains #7061's deferred handling.Following review, composition preparation now stays in input handling: prepare an empty text target without inserting a placeholder into document text, retain it during composition, and select its existing DOM-only suffix for WebKit to replace. The TextNode ownership hooks, schema/generated-JSON changes and cross-package slicing changes have been removed. The final upstream diff is five production files and two browser-test files, all in
lexical.Reproduction and evidence index · published source identity · source-only ZIP
Test plan
Before
The historical native capture on unmodified
cb21da40de69c1eedc2b9ec60001fef0d3b1770arecords an empty command list after ordinary Enter. That valid baseline is reused; it was not rerun. Raw records.The preparation regression against the preceding published implementation:
VITEST_BROWSER=chromium,webkit pnpm run test-browser packages/lexical/src/__tests__/browser/LexicalSafariComposition.test.ts -t 'composition prepares a DOM target'After
Source/test TypeScript, strict seven-file ESLint (0 errors, 0 warnings) and Prettier exited 0. The normal pre-commit hook passed and preserved the tested tree. Exact commands, outputs and reuse scope, raw logs.
A new physical capture of this implementation passed 20/20 scenarios, with 397 trusted DOM events and 91 trusted keydowns, using exact
com.apple.inputmethod.SCIM.ITABCand modifier-free native HID input in system WKWebView on macOS 27.0.1 / WebKit 22625.1.29.11.28. Cancellation, ordinary 8/13, consumed 229, real NBSP, formatted/token/empty targets, cross-paragraph selections, model updates/copies and subclass boundaries passed. Space committed你; Enter confirmed rawni. Input source and focus were restored; exit 0. Raw native records.All 134 build inputs match the capture and rebuilding reproduces its bundle byte-for-byte. Capture manifests retain their original pre-commit identity; the published source commit has the exact tested tree. Browser DOM replays are synthetic. Model-API capture cases use controlled hooks with real IME input, not remote Yjs.
The wider core/RichText browser scope combines 81 unchanged engine-files with the current three-engine file run (2075 passes, 8 skips); it is not a new all-files invocation. Unchanged generator/JSON/slicing checks and Flow reuse are documented in the index. No new full monorepo suite, E2E, full ci-check, release build, other physical OS/IME or standalone-browser capture was performed.