Repository navigation
[lexical-plain-text][lexical-rich-text] Bug Fix: Refresh iOS keyboard suggestion bar after Backspace for all locales - #8725
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
72f5be8 to
6aa5d5d
Compare
… suggestion bar after Backspace for all locales
6aa5d5d to
26f9eab
Compare
potatowagon
left a comment
There was a problem hiding this comment.
Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.
Assessment: LGTM ✅ — Good fix with solid test coverage.
Summary: This PR generalizes the iOS Backspace keyboard-suggestion-bar fix. Previously gated to navigator.language === 'ko-KR' (Korean only), it now applies to ALL iOS locales when CAN_USE_BEFORE_INPUT is available. The approach is sound: on iOS, event.preventDefault() on keydown Backspace prevents the system keyboard from refreshing its autocomplete/autocorrect suggestion bar. By returning false from KEY_BACKSPACE_COMMAND, the keydown default is left uncancelled, and the actual deletion is handled by the beforeinput deleteContentBackward handler which already fires correctly on iOS.
What I verified:
- Logic correctness: The condition change from
IS_IOS && navigator.language === 'ko-KR'toIS_IOS && CAN_USE_BEFORE_INPUTis the right broadening —CAN_USE_BEFORE_INPUTguarantees that the beforeinput pipeline will handle the deletion, making the keydown preventDefault unnecessary on ALL iOS keyboards, not just Korean. - No regressions: The rich-text path still handles the indentation outdent case BEFORE this early return (Tab+Backspace in indented blocks still calls
preventDefault). The guard is correctly placed after the outdent logic. - Both packages updated symmetrically:
lexical-plain-textandlexical-rich-textare updated with identical logic. - Test coverage: Excellent — 278-line dedicated test file covers: (a) no preventDefault on iOS, (b) full keydown→beforeinput flow still deletes correctly, (c) locale-independence verification, (d) edge cases (cursor at start, no selection), (e) repeated deletions. The
vi.mockapproach for environment flags is clean. - www compat: No API surface changes — this is internal behavior only. No new exports or changed signatures. Safe for Meta www consumers.
- CI status: Core tests (unit 22.x, unit 24.x, integrity, browser) all passing. CLA signed. Vercel deploys succeed. One e2e test still pending but unrelated to this change scope.
Minor observation: The new test uses createTestEditor() + registerRichText() but lives under packages/lexical/src/__tests__/ rather than packages/lexical-rich-text/src/__tests__/. This works fine since the mock is on lexical/src/environment, but for organization purposes the rich-text-specific tests could also live in the rich-text package. Not blocking.
Verdict: Ready to approve once the pending e2e check goes green (which is expected — the change scope doesn't affect e2e scenarios).
|
Thank you, we'll remove our patch when Lexical v0.46.0 is released. Feel free to adopt any other bug fix we may have if you have the time for it! |
|
It would be better if you'll write issues about the bugs you know about |
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts FAIL IosKeyboardSuggestions.test.ts > cursor at start of text does not delete (nothing to delete) AssertionError: expected false to be true // Object.is equality 228| expect(handled).toBe(true); FAIL IosKeyboardSuggestions.test.ts > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph AssertionError: expected false to be true // Object.is equality 301| expect(editor.dispatchCommand(KEY_BACKSPACE_COMMAND, event)).toBe(true); FAIL IosKeyboardSuggestions.test.ts > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text AssertionError: expected false to be true // Object.is equality 316| expect(editor.dispatchCommand(KEY_BACKSPACE_COMMAND, event)).toBe(true); Test Files 1 failed (1) Tests 3 failed | 10 passed (13) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit packages/lexical-rich-text packages/lexical-utils \ packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 101 passed (101) Tests 1766 passed (1766) $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done (identical output from each of the three runs) Test Files 1 passed (1) Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser packages/lexical-rich-text Test Files 2 passed (2) Tests 13 passed (13) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... No errors! $ tsc $ npx prettier --check packages/lexical-rich-text/src/index.ts \ packages/lexical-plain-text/src/index.ts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts \ packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts Checking formatting... All matched files use Prettier code style! ``` `@lexical/plain-text` has no `__tests__` directory of its own, so its two cases live in `IosKeyboardSuggestions.test.ts` alongside the rich-text ones and are covered by the first two commands. The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the document ## Description On iOS, Backspace deliberately passes through keydown handling so the `beforeinput` `deleteContentBackward` handler performs the deletion, leaving the keydown default uncancelled so the system keyboard refreshes its suggestion bar (meta#5841, meta#8725). WebKit fires no `beforeinput` at the very start of the editable region, so at that one caret position nothing performs the delegated deletion: a first-block quote never collapses back to a paragraph, and a blank first paragraph followed by another block is never removed. Handle that single position during keydown and keep the pass-through everywhere else. The guard also requires the anchor's nearest root-or-shadow-root to be the RootNode: `$isAtStartOfNode` ascends with the default `'root'` RootMode, so without that check a caret at the start of a leading table's first cell would match too, where the block-level handlers already own the position and delegated deletion is not broken. ## Test plan ### Before npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 failed (1) Tests 6 failed | 12 passed (18) FAIL > cursor at start of text does not delete (nothing to delete) FAIL > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text FAIL > iOS Backspace at the start of the first block > an empty first-block heading collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block heading is handled but does not collapse FAIL > @lexical/plain-text carries the same carve-out > a blank first paragraph before another block is removed ### After npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 18 passed (18) pnpm run test-unit Test Files 324 passed (324) Tests 6149 passed | 1 skipped (6150) VITEST_BROWSER=chromium pnpm run test-browser Test Files 25 passed (25) Tests 155 passed | 1 skipped (156) VITEST_BROWSER=webkit npx vitest --project browser --no-watch \ BackspaceBeforeInputAtEditableStart Test Files 1 passed (1) Tests 4 passed (4) The new browser test characterizes the engine assumption directly. Under Playwright WebKit it resolves IS_SAFARI=true / IS_APPLE_WEBKIT=true, so its carve-out cases assert that no `beforeinput` arrives — and they pass, which confirms the premise on real WebKit rather than only predicting it.
…Backspace at the start of the document ## Description On iOS, Backspace deliberately passes through keydown handling so the `beforeinput` `deleteContentBackward` handler performs the deletion, leaving the keydown default uncancelled so the system keyboard refreshes its suggestion bar (meta#5841, meta#8725). WebKit fires no `beforeinput` at the very start of the editable region, so at that one caret position nothing performs the delegated deletion: a first-block quote never collapses back to a paragraph, and a blank first paragraph followed by another block is never removed. Handle that single position during keydown and keep the pass-through everywhere else. The guard also requires the anchor's nearest root-or-shadow-root to be the RootNode: `$isAtStartOfNode` ascends with the default `'root'` RootMode, so without that check a caret at the start of a leading table's first cell would match too, where the block-level handlers already own the position and delegated deletion is not broken. ## Test plan ### Before npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 failed (1) Tests 6 failed | 12 passed (18) FAIL > cursor at start of text does not delete (nothing to delete) FAIL > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text FAIL > iOS Backspace at the start of the first block > an empty first-block heading collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block heading is handled but does not collapse FAIL > @lexical/plain-text carries the same carve-out > a blank first paragraph before another block is removed ### After npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 18 passed (18) pnpm run test-unit Test Files 324 passed (324) Tests 6149 passed | 1 skipped (6150) VITEST_BROWSER=chromium pnpm run test-browser Test Files 25 passed (25) Tests 155 passed | 1 skipped (156) VITEST_BROWSER=webkit npx vitest --project browser --no-watch \ BackspaceBeforeInputAtEditableStart Test Files 1 passed (1) Tests 4 passed (4) The new browser test characterizes the engine assumption directly. Under Playwright WebKit it resolves IS_SAFARI=true / IS_APPLE_WEBKIT=true, so its carve-out cases assert that no `beforeinput` arrives — and they pass, which confirms the premise on real WebKit rather than only predicting it.
…Backspace at the start of the document ## Description On iOS, Backspace deliberately passes through keydown handling so the `beforeinput` `deleteContentBackward` handler performs the deletion, leaving the keydown default uncancelled so the system keyboard refreshes its suggestion bar (meta#5841, meta#8725). WebKit fires no `beforeinput` at the very start of the editable region, so at that one caret position nothing performs the delegated deletion and the first block's own start-of-Backspace semantic never runs. What that costs depends on the node: a first-block quote or code block does not collapse to a paragraph, an empty heading does not either (a non-empty one is unaffected, since `HeadingNode.collapseAtStart` only converts when empty), and in plain text a blank first paragraph followed by another block is not removed. Nodes that register their own Backspace handler are unaffected. `@lexical/list` handles a first list item at `COMMAND_PRIORITY_BEFORE_EDITOR`, so lists never reach this path and do not reproduce. Handle that single position during keydown and keep the pass-through everywhere else. The guard also requires the anchor's nearest root-or-shadow-root to be the RootNode: `$isAtStartOfNode` ascends with the default `'root'` RootMode, so without that check a caret at the start of a leading table's first cell would match too, where the block-level handlers already own the position and delegated deletion is not broken. ## Test plan ### Before npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 failed (1) Tests 7 failed | 12 passed (19) FAIL > cursor at start of text does not delete (nothing to delete) FAIL > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text FAIL > iOS Backspace at the start of the first block > an empty first-block heading collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block heading is handled but does not collapse FAIL > iOS Backspace at the start of the first block > a non-empty first-block code node collapses to a paragraph FAIL > @lexical/plain-text carries the same carve-out > a blank first paragraph before another block is removed ### After npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 19 passed (19) pnpm run test-unit Test Files 324 passed (324) Tests 6150 passed | 1 skipped (6151) VITEST_BROWSER=chromium pnpm run test-browser Test Files 25 passed (25) Tests 155 passed | 1 skipped (156) VITEST_BROWSER=webkit npx vitest --project browser --no-watch \ BackspaceBeforeInputAtEditableStart Test Files 1 passed (1) Tests 4 passed (4) The new browser test characterizes the engine assumption directly. Under Playwright WebKit it resolves IS_SAFARI=true / IS_APPLE_WEBKIT=true, so its carve-out cases assert that no `beforeinput` arrives — and they pass, which confirms the premise on real WebKit rather than only predicting it.
…Backspace at the start of the document ## Description On iOS, Backspace deliberately passes through keydown handling so the `beforeinput` `deleteContentBackward` handler performs the deletion, leaving the keydown default uncancelled so the system keyboard refreshes its suggestion bar (meta#5841, meta#8725). WebKit fires no `beforeinput` for Backspace wherever nothing precedes the caret in the editing host, so the pass-through has nothing to delegate to at any such position and the block's own start-of-Backspace semantic never runs. What that costs depends on the node: a first-block quote or code block does not collapse to a paragraph, an empty heading does not either (a non-empty one is unaffected, since `HeadingNode.collapseAtStart` only converts when empty), and in plain text a blank first paragraph followed by another block is not removed. Not every such position needs handling, so the guard matches only the top-level case, where `collapseAtStart` is the only thing that would act. `@lexical/list` handles a first list item itself at `COMMAND_PRIORITY_BEFORE_EDITOR`, so lists never reach this path and do not reproduce; Backspace at the start of a leading table's first cell is already a no-op, so iOS matches every other platform there. Handle that single position during keydown and keep the pass-through everywhere else. The guard requires the anchor's nearest root-or-shadow-root to be the RootNode: `$isAtStartOfNode` ascends with the default `'root'` RootMode and would otherwise match those nested positions too. ## Test plan ### Before npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 failed (1) Tests 7 failed | 12 passed (19) FAIL > cursor at start of text does not delete (nothing to delete) FAIL > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text FAIL > iOS Backspace at the start of the first block > an empty first-block heading collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block heading is handled but does not collapse FAIL > iOS Backspace at the start of the first block > a non-empty first-block code node collapses to a paragraph FAIL > @lexical/plain-text carries the same carve-out > a blank first paragraph before another block is removed ### After npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 19 passed (19) pnpm run test-unit Test Files 324 passed (324) Tests 7291 passed | 1 skipped (7292) VITEST_BROWSER=chromium pnpm run test-browser Test Files 25 passed (25) Tests 156 passed | 1 skipped (157) VITEST_BROWSER=webkit npx vitest --project browser --no-watch \ BackspaceBeforeInputAtEditableStart Test Files 1 passed (1) Tests 5 passed (5) The new browser test characterizes the engine assumption directly. Under Playwright WebKit it resolves IS_SAFARI=true / IS_APPLE_WEBKIT=true, so its carve-out cases assert that no `beforeinput` arrives — and they pass, which confirms the premise against WebKit rather than only predicting it.
…Backspace at the start of the document ## Description On iOS, Backspace deliberately passes through keydown handling so the `beforeinput` `deleteContentBackward` handler performs the deletion, leaving the keydown default uncancelled so the system keyboard refreshes its suggestion bar (meta#5841, meta#8725). WebKit fires no `beforeinput` for Backspace wherever nothing precedes the caret in the editing host, so positions that rely on this iOS pass-through have nothing to delegate to. What that costs depends on the node: a first-block quote or code block does not collapse to a paragraph, an empty heading does not either (a non-empty one is unaffected, since `HeadingNode.collapseAtStart` only converts when empty), and in plain text a blank first paragraph followed by another block is not removed. Not every such position needs handling, so the guard matches only the top-level case, where `collapseAtStart` is the only thing that would act. `@lexical/list` handles a first list item itself at `COMMAND_PRIORITY_BEFORE_EDITOR`, so lists never reach this path and do not reproduce; Backspace at the start of a leading table's first cell is already a no-op, so iOS matches every other platform there. Handle that single position during keydown and keep the pass-through everywhere else. The guard requires the anchor's nearest root-or-shadow-root to be the RootNode: `$isAtStartOfNode` ascends with the default `'root'` RootMode and would otherwise match those nested positions too. ## Test plan ### Before npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 failed (1) Tests 7 failed | 12 passed (19) FAIL > cursor at start of text does not delete (nothing to delete) FAIL > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text FAIL > iOS Backspace at the start of the first block > an empty first-block heading collapses to a paragraph FAIL > iOS Backspace at the start of the first block > a non-empty first-block heading is handled but does not collapse FAIL > iOS Backspace at the start of the first block > a non-empty first-block code node collapses to a paragraph FAIL > @lexical/plain-text carries the same carve-out > a blank first paragraph before another block is removed ### After npx vitest run --config vitest.config.mts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 19 passed (19) pnpm run test-unit Test Files 324 passed (324) Tests 7291 passed | 1 skipped (7292) pnpm run test-e2e-chromium 22 skipped 861 passed (6.1m) VITEST_BROWSER=chromium pnpm run test-browser Test Files 25 passed (25) Tests 156 passed | 1 skipped (157) VITEST_BROWSER=webkit npx vitest --project browser --no-watch \ BackspaceBeforeInputAtEditableStart Test Files 1 passed (1) Tests 5 passed (5) The new browser test characterizes the engine assumption directly. Under Playwright WebKit it resolves IS_SAFARI=true / IS_APPLE_WEBKIT=true, so its carve-out cases assert that no `beforeinput` arrives — and they pass, which confirms the premise against WebKit rather than only predicting it.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). There, the iOS 10-key Korean IME workaround added by meta#8475 applies any non-collapsed `targetRange` with `applyDOMRange()` and deletes it with `removeText()`. That is correct for the IME's jamo deletes, which stay inside one text node, but WebKit reports a non-collapsed range for an ordinary Backspace too. At the start of a block it reports the range from the previous editable position to the caret, skipping any `contenteditable=false` node in between: with `<p>abc</p><div contenteditable="false">…</div><p></p>` and the caret in the empty paragraph, the range is `#text(abc)@3 .. P@0`. `removeText()` deletes everything between the two points and merges the blocks, which skips the rules `RangeSelection.deleteCharacter` applies there: - an empty paragraph after a block decorator should be removed and the decorator selected (meta#7155); on iOS the decorator is deleted too and the caret lands at the end of "abc"; - at the start of a text paragraph after a block decorator only the decorator should be deleted (meta#7155); on iOS the two paragraphs are merged as well; - an empty paragraph before a heading should be removed and the heading kept (meta#8493); on iOS the heading is merged into the paragraph; - an isolated decorator (`isIsolated()`) is never deleted by Backspace (meta#7155), but WebKit reports `#text(ab)@2 .. SPAN@0` across an inline `contenteditable=false` element inside one paragraph, and on iOS it is deleted. This resolves the range on a clone of the selection and takes the fast path only when both ends share the same nearest block element and the range contains no decorator. Anything wider falls through to `DELETE_CHARACTER_COMMAND` from the untouched caret, which is what every other platform runs for Backspace (their keydown handler calls `preventDefault()`, so they never see a `targetRange`). The IME case is unchanged: a jamo delete is a text-only range inside one block, and so is a range straddling two adjacent text nodes in one paragraph. The keydown pass-through is untouched, so the suggestion bar keeps refreshing, and the fallback already calls `event.preventDefault()`, so nothing is deleted twice. Resolving on a clone also means a range that `applyDOMRange()` resolves to a collapsed point no longer moves the caret before the fallback runs. List items are unaffected: `@lexical/list` handles Backspace at their start on keydown, ahead of the iOS pass-through (meta#8829). Out of scope: a text-only range inside one block still takes the `removeText()` fast path, so segmented and token text nodes delete differently there than on other platforms. That predates this change (meta#8475) and needs the fast path itself, which the IME depends on. Backspace at the very start of the first block, where WebKit fires no `beforeinput` at all, is a separate defect fixed on its own in the first-block iOS Backspace change. ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph AssertionError: expected { json: { root: { …(8) } }, …(1) } to deeply equal { json: { root: { …(8) } }, …(1) } (x4) Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts Test Files 1 passed (1) Tests 10 passed (10) $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 345 passed (345) Tests 5740 passed | 1 skipped (5741) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc $ npx prettier --check packages/lexical/src/LexicalEvents.ts \ packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Checking formatting... All matched files use Prettier code style! ``` Each new unit test runs the same document through the iOS `targetRange` path and through `DELETE_CHARACTER_COMMAND` and asserts the results match. The one missing from Before, a plain paragraph boundary, passes before the fix too (merging gives the same result either way) and guards that boundary. The existing IME tests pass unchanged. The browser test pins the engine behavior the unit tests fake with a `StaticRange`: it presses a real Backspace in a plain `contenteditable` with no editor attached, and asserts that WebKit reports a non-collapsed range that contains the `contenteditable=false` block, from both an empty and a text paragraph. It runs on WebKit only. Firefox reports a range that does not contain the block in the empty-paragraph case, and the fix only runs on iOS. Chromium and Firefox skip it, so its signal comes from the macOS + webkit job of the extended matrix. Not yet verified on a physical iOS device. To check there: - Backspace in an empty paragraph after a block decorator removes the paragraph and selects the decorator, and a second Backspace deletes the decorator without the page scrolling to the top (see meta#9113); - Backspace at the start of a text paragraph after a block decorator, and between two plain paragraphs, matches desktop; - Backspace at the start of a heading after an empty paragraph keeps the heading; - 10-key Korean input of "안녕하세요" is correct (meta#8475) and 2-set Korean composition is unaffected; - the suggestion bar still refreshes after Backspace; - press-and-hold Backspace and Backspace over a range selection delete once.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). There, the iOS 10-key Korean IME workaround added by meta#8475 applies any non-collapsed `targetRange` with `applyDOMRange()` and deletes it with `removeText()`. That is correct for the IME's jamo deletes, which stay inside one text node, but WebKit reports a non-collapsed range for an ordinary Backspace too. At the start of a block it reports the range from the previous editable position to the caret, skipping any `contenteditable=false` node in between: with `<p>abc</p><div contenteditable="false">…</div><p></p>` and the caret in the empty paragraph, the range is `#text(abc)@3 .. P@0`. `removeText()` deletes everything between the two points and merges the blocks, which skips the rules `RangeSelection.deleteCharacter` applies there: - an empty paragraph after a block decorator should be removed and the decorator selected (meta#7155); on iOS the decorator is deleted too and the caret lands at the end of "abc"; - at the start of a text paragraph after a block decorator only the decorator should be deleted (meta#7155); on iOS the two paragraphs are merged as well; - an empty paragraph before a heading should be removed and the heading kept (meta#8493); on iOS the heading is merged into the paragraph; - an isolated decorator (`isIsolated()`) is never deleted by Backspace (meta#7155), but WebKit reports `#text(ab)@2 .. SPAN@0` across an inline `contenteditable=false` element inside one paragraph, and on iOS it is deleted. This resolves the range on a clone of the selection and takes the fast path only when both ends resolve inside the same, non-null nearest block element and the range contains no decorator. Anything wider falls through to `DELETE_CHARACTER_COMMAND` from the untouched caret, which is what every other platform runs for Backspace (their keydown handler calls `preventDefault()`, so they never see a `targetRange`). The IME case is unchanged: a jamo delete is a text-only range inside one block, and so is a range straddling two adjacent text nodes in one paragraph. The keydown pass-through is untouched, so the suggestion bar keeps refreshing, and the fallback already calls `event.preventDefault()`, so nothing is deleted twice. Resolving on a clone also means a range that `applyDOMRange()` resolves to a collapsed point no longer moves the caret before the fallback runs. The same-block test requires a non-null block on each end rather than comparing the two `$findMatchingParent()` results directly. That helper stops before the `RootNode` and returns null, so two points with no block ancestor would compare equal and read as "same block". This part is hardening, not a reachable fix: I could not construct a document where it happens, because `applyDOMRange()` normalizes a root-level DOM offset down into a child block, so both ends resolve to a paragraph or heading element point, or to a text point inside one. Four shapes were probed (two empty paragraphs, an empty paragraph followed by a text paragraph, a single empty paragraph, and an empty paragraph followed by a heading) and none produced a point on the `RootNode`. No test pins the null rejection for that reason; a test that exercises it would pass without it. Both lookups are hoisted into locals, which also drops a duplicated tree walk. List items are unaffected: `@lexical/list` handles Backspace at their start on keydown, ahead of the iOS pass-through (meta#8829). Out of scope: a text-only range inside one block still takes the `removeText()` fast path, so segmented and token text nodes delete differently there than on other platforms. That predates this change (meta#8475) and needs the fast path itself, which the IME depends on. Backspace at the very start of the first block, where WebKit fires no `beforeinput` at all, is a separate defect fixed on its own in the first-block iOS Backspace change. ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph AssertionError: expected { json: { root: { …(8) } }, …(1) } to deeply equal { json: { root: { …(8) } }, …(1) } (x4) Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts Test Files 1 passed (1) Tests 10 passed (10) $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 345 passed (345) Tests 5740 passed | 1 skipped (5741) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc $ npx prettier --check packages/lexical/src/LexicalEvents.ts \ packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Checking formatting... All matched files use Prettier code style! ``` Each new unit test runs the same document through the iOS `targetRange` path and through `DELETE_CHARACTER_COMMAND` and asserts the results match. The one missing from Before, a plain paragraph boundary, passes before the fix too (merging gives the same result either way) and guards that boundary. The existing IME tests pass unchanged. The browser test pins the engine behavior the unit tests fake with a `StaticRange`: it presses a real Backspace in a plain `contenteditable` with no editor attached, and asserts that WebKit reports a non-collapsed range that contains the `contenteditable=false` block, from both an empty and a text paragraph. It runs on WebKit only. Firefox reports a range that does not contain the block in the empty-paragraph case, and the fix only runs on iOS. Chromium and Firefox skip it, so its signal comes from the macOS + webkit job of the extended matrix. The non-null block requirement was added after the runs above and re-verified on its own. The file and test counts differ from the run above because the branch was rebased onto a newer `main` in between: ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ pnpm run tsc $ tsc $ pnpm exec eslint packages/lexical/src/LexicalEvents.ts $ pnpm exec prettier --check packages/lexical/src/LexicalEvents.ts Checking formatting... All matched files use Prettier code style! ``` It rejects strictly more ranges than the version the browser run above exercised, and is behavior-preserving for every document shape that could be constructed, so those results stand. The browser test was not re-run for it, since it characterizes the engine rather than this predicate. Not yet verified on a physical iOS device. To check there: - Backspace in an empty paragraph after a block decorator removes the paragraph and selects the decorator, and a second Backspace deletes the decorator without the page scrolling to the top (see meta#9113); - Backspace at the start of a text paragraph after a block decorator, and between two plain paragraphs, matches desktop; - Backspace at the start of a heading after an empty paragraph keeps the heading; - 10-key Korean input of "안녕하세요" is correct (meta#8475) and 2-set Korean composition is unaffected; - the suggestion bar still refreshes after Backspace; - press-and-hold Backspace and Backspace over a range selection delete once.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. List-item Backspace is also unaffected, since `@lexical/list` handles it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5986 passed | 1 skipped (5987) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
Description
Current behavior: On iOS, the system keyboard's autocomplete suggestion bar (the word-suggestion strip above the keyboard) and autocorrect candidates do not update after pressing Backspace inside a Lexical editor. They remain stuck on the suggestion shown before the deletion
Root cause: In
KEY_BACKSPACE_COMMAND, Lexical callsevent.preventDefault()on the keydown event before dispatchingDELETE_CHARACTER_COMMAND. On iOS Safari, blocking the keydown default causes the system to treat the Backspace as "externally handled" — it stops tracking the text-editing operation and never refreshes the suggestion bar.Fix: Return false from
KEY_BACKSPACE_COMMANDfor all iOS keyboards whenCAN_USE_BEFORE_INPUTis true (i.e. skipevent.preventDefault()on keydown). The actual deletion is unchanged — thebeforeinputdeleteContentBackward handler already fires on iOS, callsevent.preventDefault()onbeforeinput, and dispatchesDELETE_CHARACTER_COMMAND. iOS sees an unblocked Backspace keydown and keeps its suggestion-bar state machine running.This extends the existing Korean-only guard (
IS_IOS && navigator.language === 'ko-KR', added in #5841) to all iOS localesCloses #7994 #7614 #7565
Test plan
Before
On an iOS device, open a Lexical rich-text editor, type a word (e.g. "hello"), then press Backspace. The suggestion bar above the keyboard does not update — it remains frozen on the suggestion from before the deletion.
After
trim.F7CF8E71-682F-4A27-BEE6-C6169AA5108B.MOV
After pressing Backspace the suggestion bar refreshes immediately, matching the behavior of native
<input>and<textarea>elements.