[lexical-rich-text] Bug Fix: preserve typing after selected block decorators in Firefox and WebKit #9904
[vc]: #DFSeXg7brxw3s/QLh8PyqyvdqXwweb4+yDygwbY0qAE=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJsZXhpY2FsIiwicHJvamVjdElkIjoicHJqX01SYU1PMzFlRklrWTYxU0JxcVBEUjJPank4cVAiLCJ2MCI6ZmFsc2UsInJvb3REaXJlY3RvcnkiOiJwYWNrYWdlcy9sZXhpY2FsLXdlYnNpdGUiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vZmJvcGVuc291cmNlL2xleGljYWwvRWZvaW1zZ210MUxlM2c5YVdGTmZrS1lyUHZKYSIsInByZXZpZXdVcmwiOiJsZXhpY2FsLWdpdC1mb3JrLXRob3JuMC1maXgtc2VsZWN0ZWQtYmxvY2stdHlwaW5nLWZib3BlbnNvdXJjZS52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IkRFUExPWUVEIn0seyJuYW1lIjoibGV4aWNhbC1wbGF5Z3JvdW5kIiwicHJvamVjdElkIjoicHJqX2VhODJ2TGo2ODRYelNSZGVPN0pTZDBRTmthd3MiLCJ2MCI6ZmFsc2UsInJvb3REaXJlY3RvcnkiOiJwYWNrYWdlcy9sZXhpY2FsLXBsYXlncm91bmQiLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vZmJvcGVuc291cmNlL2xleGljYWwtcGxheWdyb3VuZC85dW9HYlhuTWRieUtWRkVLUjJSZWV1a3RGcVNLIiwicHJldmlld1VybCI6ImxleGljYWwtcGxheWdyb3VuZC1naXQtZm9yay10aG9ybjAtZml4LXNlbGUtZWVkZDJjLWZib3BlbnNvdXJjZS52ZXJjZWwuYXBwIiwibmV4dENvbW1pdFN0YXR1cyI6IkRFUExPWUVEIn1dLCJyZXF1ZXN0UmV2aWV3VXJsIjoiaHR0cHM6Ly92ZXJjZWwuY29tL3ZlcmNlbC1hZ2VudC9yZXF1ZXN0LXJldmlldz9vd25lcj1tZXRhJnJlcG89bGV4aWNhbCZwcj05OTA0In0=
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated |
| :--- | :----- | :------ | :------ |
| <a href="https://vercel.com/fbopensource/lexical"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_MRaMO31eFIkY61SBqqPDR2Ojy8qP&teamId=team_QNIQyH5DJlqUjeCckcCcBEjE&s=32" width="16" height="16" align="middle" alt="" /></sup></a> lexical | !Ready Ready | Preview | <relative-time datetime="2026-11-16T00:34:33.464Z">Nov 16, 2026 12:34am UTC</relative-time> |
| <a href="https://vercel.com/fbopensource/lexical-playground"><sup><img src="https://vercel.com/api/www/avatar?projectId=prj_ea82vLj684XzSRdeO7JSd0QNkaws&teamId=team_QNIQyH5DJlqUjeCckcCcBEjE&s=32" width="16" height="16" align="middle" alt="" /></sup></a> lexical-playground | !Ready Ready | Preview | <relative-time datetime="2026-11-16T00:34:33.464Z">Nov 16, 2026 12:34am UTC</relative-time> |
<a href="https://vercel.com/vercel-agent/request-review?owner=meta&repo=lexical&pr=9904" rel="noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://agents-vade-review.vercel.sh/request-review-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://agents-vade-review.vercel.sh/request-review-light.svg"><img src="https://agents-vade-review.vercel.sh/request-review-light.svg" alt="Request Review"></picture></a>
AI review status for this pull request.
| Review status | Updated |
| :--- | :--- |
| 🟢 Reviewed (for maintainers only) | <relative-time datetime="2026-11-16T01:00:03Z">Nov 16, 2026, 1:00 AM UTC</relative-time> |
<!-- codebunny-status:1 r=318341089 p=9904 rv=2 -->
<details><summary><b>lexical</b></summary><p>
npm i https://pkg.pr.new/lexical@9904
</p></details>
<details><summary><b>@lexical/a11y</b></summary><p>
npm i https://pkg.pr.new/@lexical/a11y@9904
</p></details>
<details><summary><b>@lexical/clipboard</b></summary><p>
npm i https://pkg.pr.new/@lexical/clipboard@9904
</p></details>
<details><summary><b>@lexical/code</b></summary><p>
npm i https://pkg.pr.new/@lexical/code@9904
</p></details>
<details><summary><b>@lexical/code-core</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-core@9904
</p></details>
<details><summary><b>@lexical/code-prism</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-prism@9904
</p></details>
<details><summary><b>@lexical/code-shiki</b></summary><p>
npm i https://pkg.pr.new/@lexical/code-shiki@9904
</p></details>
<details><summary><b>@lexical/compiler</b></summary><p>
npm i https://pkg.pr.new/@lexical/compiler@9904
</p></details>
<details><summary><b>@lexical/devtools-core</b></summary><p>
npm i https://pkg.pr.new/@lexical/devtools-core@9904
</p></details>
<details><summary><b>@lexical/dragon</b></summary><p>
npm i https://pkg.pr.new/@lexical/dragon@9904
</p></details>
<details><summary><b>@lexical/eslint-plugin</b></summary><p>
npm i https://pkg.pr.new/@lexical/eslint-plugin@9904
</p></details>
<details><summary><b>@lexical/extension</b></summary><p>
npm i https://pkg.pr.new/@lexical/extension@9904
</p></details>
<details><summary><b>@lexical/fast-check</b></summary><p>
npm i https://pkg.pr.new/@lexical/fast-check@9904
</p></details>
<details><summary><b>@lexical/file</b></summary><p>
npm i https://pkg.pr.new/@lexical/file@9904
</p></details>
<details><summary><b>@lexical/hashtag</b></summary><p>
npm i https://pkg.pr.new/@lexical/hashtag@9904
</p></details>
<details><summary><b>@lexical/headless</b></summary><p>
npm i https://pkg.pr.new/@lexical/headless@9904
</p></details>
<details><summary><b>@lexical/history</b></summary><p>
npm i https://pkg.pr.new/@lexical/history@9904
</p></details>
<details><summary><b>@lexical/html</b></summary><p>
npm i https://pkg.pr.new/@lexical/html@9904
</p></details>
<details><summary><b>@lexical/internal</b></summary><p>
npm i https://pkg.pr.new/@lexical/internal@9904
</p></details>
<details><summary><b>@lexical/link</b></summary><p>
npm i https://pkg.pr.new/@lexical/link@9904
</p></details>
<details><summary><b>@lexical/list</b></summary><p>
npm i https://pkg.pr.new/@lexical/list@9904
</p></details>
<details><summary><b>@lexical/mark</b></summary><p>
npm i https://pkg.pr.new/@lexical/mark@9904
</p></details>
<details><summary><b>@lexical/markdown</b></summary><p>
npm i https://pkg.pr.new/@lexical/markdown@9904
</p></details>
<details><summary><b>@lexical/mdast</b></summary><p>
npm i https://pkg.pr.new/@lexical/mdast@9904
</p></details>
<details><summary><b>@lexical/offset</b></summary><p>
npm i https://pkg.pr.new/@lexical/offset@9904
</p></details>
<details><summary><b>@lexical/overflow</b></summary><p>
npm i https://pkg.pr.new/@lexical/overflow@9904
</p></details>
<details><summary><b>@lexical/plain-text</b></summary><p>
npm i https://pkg.pr.new/@lexical/plain-text@9904
</p></details>
<details><summary><b>@lexical/react</b></summary><p>
npm i https://pkg.pr.new/@lexical/react@9904
</p></details>
<details><summary><b>@lexical/rich-text</b></summary><p>
npm i https://pkg.pr.new/@lexical/rich-text@9904
</p></details>
<details><summary><b>@lexical/selection</b></summary><p>
npm i https://pkg.pr.new/@lexical/selection@9904
</p></details>
<details><summary><b>@lexical/table</b></summary><p>
npm i https://pkg.pr.new/@lexical/table@9904
</p></details>
<details><summary><b>@lexical/tailwind</b></summary><p>
npm i https://pkg.pr.new/@lexical/tailwind@9904
</p></details>
<details><summary><b>@lexical/text</b></summary><p>
npm i https://pkg.pr.new/@lexical/text@9904
</p></details>
<details><summary><b>@lexical/utils</b></summary><p>
npm i https://pkg.pr.new/@lexical/utils@9904
</p></details>
<details><summary><b>@lexical/y</b></summary><p>
npm i https://pkg.pr.new/@lexical/y@9904
</p></details>
<details><summary><b>@lexical/yjs</b></summary><p>
npm i https://pkg.pr.new/@lexical/yjs@9904
</p></details>
_commit: <a href="https://github.com/meta/lexical/runs/133018701467"><code>bcfaa24</code></a>_
While a block decorator is node-selected, this guard lets through keys pressed on a focused <button> or <select> inside it, because $isEventFromEmbeddedInput covers only <input>, <textarea> and foreign contentEditable. Space then stops activating the button and inserts a " " paragraph after the block, and select type-ahead (q) inserts a q paragraph. On main both keys go to the control. The check Backspace and Delete already make keeps them there, and this PR's tests still pass with it:
!$isEventFromEmbeddedInput(event) &&
!$isTargetWithinDecorator(event.target as HTMLElement) &&
Optional: macOS layouts type printable characters with Option (altKey: true, for example å, ©, or ą on Polish Pro). Unless the browser also reports AltGraph, these keys skip this path and Safari still drops them. Lexical binds no Option+printable shortcut, so altKey alone could be accepted when IS_APPLE (exported by lexical) is true.
Requested change
1. Native controls inside a selected block decorator lose Space and typed letters (packages/lexical-rich-text/src/index.ts:1324-1341). The new guard skips only events for which $isEventFromEmbeddedInput is true, and that covers <input>, <textarea> and foreign contentEditable. Suppose a block decorator is node-selected and a <button> or <select> inside it has focus. Clicking the control is enough to get there, because the rich-text CLICK_COMMAND handler keeps the NodeSelection for clicks inside the selected node. The keydown is then prevented and the key is inserted after the block. Space no longer activates the button and inserts a " " paragraph instead. Typing q on the <select> inserts a q paragraph instead of choosing the matching option. On main both keys go to the control. AGENTS.md's Backwards Compatibility section asks for existing behavior to be kept intact, and this changeset's own Verify: line promises that embedded controls keep their normal behavior. Suggested fix; this PR's browser and unit tests still pass with it in Chromium and Firefox:
!$isEventFromEmbeddedInput(event) &&
+ !$isTargetWithinDecorator(event.target as HTMLElement) &&
$selectAfterBlockDecorator(selection)
$isTargetWithinDecorator is the check the Backspace and Delete handlers already make. After a click on a divider, the key's target is the editor root, so the cases this PR fixes still insert. A browser case with a focused button or select in the selected block would keep this covered.
Optional, non-blocking
index.ts:1330-1332: on macOS, printable characters typed with Option arrive with altKey: true (å, ©, or ą on Polish Pro). Unless the browser also reports AltGraph, they still take the old path, which Safari drops. Lexical binds no Option+printable shortcut, so the guard could accept altKey alone when IS_APPLE (exported by lexical) is true.extended-tests label so the Firefox and macOS WebKit jobs run on this PR..changeset/rich-text-type-after-selected-block-decorator.md is still unreleased and covers the same behavior. #9876 updated that pending entry instead of adding a new one; doing the same here would leave one changelog entry (CONTRIBUTING.md, Changesets).The new browser spec reproduces the Firefox bug without the fix and passes with it, and moving the selection logic into $selectAfterBlockDecorator keeps the behavior from #9876 unchanged. Thanks for tracking this down.
Automated review (maintainer link)
<!-- codebunny-pub:1 k=2b27c52d06b1de0973b0a1935ea9e7589d65ebee2c3cfb30df3870658cc2c386 -->
This looks good to me, and thanks for the quick follow-up on native controls. The new $isTargetWithinDecorator(getComposedEventTarget(event)) condition (packages/lexical-rich-text/src/index.ts:1335) leaves Space on a focused <button>, type-ahead on a focused <select>, and typing in a nested editor inside the selected block to their target, and the two new browser cases fail without it and pass with it. The new spec also reproduces the original Firefox bug: its typing cases fail without the fix and pass with it.
Optional, non-blocking suggestions
1. Option-typed characters on macOS (index.ts:1332-1333). The guard accepts altKey only together with getModifierState('AltGraph'). macOS layouts type printable characters with Option (å, ©, or ą on Polish Pro), and unless Safari reports AltGraph for them, they still take the old path that Safari drops. Lexical's built-in shortcuts bind no Option-only printable key, so accepting altKey alone when IS_APPLE is true would cover them.
2. Two guarded paths have no test. Neither the AltGraph branch nor typing into a nested editor inside the selected decorator is covered. A browser case for each, as AGENTS.md's Testing Strategy recommends for real input behaviour, would keep them from regressing.
3. CI coverage. The default browser job runs Linux Chromium only, and there the new spec also passes without the fix. A maintainer may want to add the extended-tests label so the Firefox and macOS WebKit jobs run on this PR.
4. One changelog entry. .changeset/rich-text-type-after-selected-block-decorator.md is still unreleased and describes the same behaviour. Folding this entry into it, with Firefox and Safari named in its Verify: line, would leave a single release note (AGENTS.md, Changesets).
Automated review (maintainer link)
<!-- codebunny-pub:1 k=66f7d689084794587767d26668de401f0c734bb24aaebcacdf84e405b5e40ea1 -->
Optional: this guard never reads event.defaultPrevented. A higher-priority KEY_DOWN_COMMAND or KEY_SPACE_COMMAND listener that calls preventDefault() but returns false used to stop the character in Chromium (the browser fires no beforeinput), while here the key is inserted anyway. Checking it keeps that behavior:
$isNodeSelection(selection) &&
!event.defaultPrevented &&
Nit: event.key.length === 1 skips printable keys whose value is a surrogate pair or several characters, so those are still dropped after a selected block in Firefox and WebKit. Named key values are ASCII words (Enter, Dead, Process, Unidentified), so event.key.length === 1 || !/^[A-Za-z][A-Za-z0-9]*$/.test(event.key) would admit them without letting a named key through.
Optional: these cases mock IS_APPLE in jsdom and dispatch the command directly. A case in the browser spec like the AltGraph one (altKey: true, key: 'å'), skipped unless IS_APPLE, would exercise the Option branch with a real event on the macOS Firefox and WebKit jobs, per the browser-test tier in AGENTS.md.
Nit: without this fix Firefox drops everything typed after a selected divider, not only the first character. Per .changeset/README.md the summary describes the change from the user's side, for example:
[fix] Text typed after a selected block decorator now appears in Firefox and WebKit
This looks good, and thanks for the detailed before/after test plan. Typing after a selected divider now works in Firefox, and Chromium behaves exactly as before. Everything below is optional and non-blocking.
Optional suggestions
1. Honor a cancelled keydown (packages/lexical-rich-text/src/index.ts:1329-1340). $insertTextAfterBlockDecorator does not check event.defaultPrevented. Before this change, a higher-priority KEY_DOWN_COMMAND or KEY_SPACE_COMMAND listener that called preventDefault() but returned false still stopped the character in Chromium, because the browser then fires no beforeinput; with this change the key is inserted anyway. Adding !event.defaultPrevented to the guard keeps the previous behavior.
2. Exercise the Option path in a real browser. The Option cases in packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionTyping.test.ts:118-137 mock IS_APPLE in jsdom and dispatch the command directly. AGENTS.md (Testing Strategy) puts real input behavior in browser tests; a case in the browser spec like the AltGraph one (altKey: true, key: 'å'), skipped unless IS_APPLE, would run on the macOS Firefox and WebKit jobs.
3. Key values longer than one UTF-16 unit (index.ts:1331). event.key.length === 1 skips printable keys whose value is a surrogate pair or several characters, so those are still dropped after a selected block. Named key values are ASCII words (Enter, Dead, Process), so event.key.length === 1 || !/^[A-Za-z][A-Za-z0-9]*$/.test(event.key) would admit them without letting a named key through.
4. Changeset wording (.changeset/selected-block-keyboard-typing.md:5). Without this fix Firefox drops everything typed after a selected divider, not only the first character. .changeset/README.md asks for a summary of the change from the user's side, for example [fix] Text typed after a selected block decorator now appears in Firefox and WebKit.
Automated review (maintainer link)
<!-- codebunny-pub:1 k=316ca54a96f6a980f1d2af5aa3cc33d13e826dc4c7f20e0fd83015e1f6653138 -->
Optional: the fromEditor !== editor check at line 1511 covers BEFORE_INPUT_COMMAND, but this listener (and the KEY_SPACE_COMMAND one at line 2127) also runs, in the parent's state, for keys a nested editor dispatches. Inside the selected decorator $isTargetWithinDecorator keeps the key in the child; for a nested editor rendered outside the decorator's DOM (a portal, like the playground's sticky note), with the parent's node selection retained as the nested test retains it, typing q leaves the child unchanged and inserts a q paragraph after the divider in the parent, in Chromium and Firefox. Threading fromEditor through keeps the key in the child, and the spec still passes:
const $insertTextAfterBlockDecorator = (
event: KeyboardEvent,
fromEditor: LexicalEditor,
): boolean => {
if (fromEditor !== editor) {
return false;
}
// ...unchanged
};
// KEY_DOWN_COMMAND
(event, fromEditor) =>
event.key !== ' ' && $insertTextAfterBlockDecorator(event, fromEditor),
// KEY_SPACE_COMMAND: (event, fromEditor) => { ... }
return $insertTextAfterBlockDecorator(event, fromEditor);
This looks good: typing after a selected divider now works in Firefox and WebKit, Chromium's result is unchanged, and the new cancellation, nested-editor and native-control cases cover the earlier gaps. The consolidated changeset reads well and follows .changeset/README.md. A few optional, non-blocking suggestions:
1. Optional: apply the ownership check to the keydown path too (packages/lexical-rich-text/src/index.ts:1522-1527 and :2113-2130). The new fromEditor !== editor check at :1511 covers BEFORE_INPUT_COMMAND, but a nested editor's KEY_DOWN_COMMAND and KEY_SPACE_COMMAND also reach the parent's listeners, in the parent's state. Inside the selected decorator $isTargetWithinDecorator keeps the key in the child. For a nested editor rendered outside the decorator's DOM (a portal, like the playground's sticky note), with the parent's node selection retained the way your nested test retains it, typing q leaves the child unchanged and inserts a q paragraph after the divider in the parent, in Chromium and Firefox. Passing fromEditor into $insertTextAfterBlockDecorator and returning false when it is not editor keeps the key in the child, and the existing spec still passes with it. A browser case that mounts the child root outside the decorator would pin it.
2. Optional: a real-browser Option case. The Option-character cases (packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionTyping.test.ts:118-137) mock IS_APPLE in jsdom and dispatch the command directly. AGENTS.md's testing strategy puts real input events in browser tests; a copy of the AltGraph browser case with altKey: true, key: 'å', skipped unless IS_APPLE, would run on the macOS WebKit and Firefox browser jobs.
3. Nit: multi-unit key values. event.key.length === 1 (index.ts:1332) still drops a printable key whose value is a surrogate pair or several characters; event.key.length === 1 || !/^[A-Za-z][A-Za-z0-9]*$/.test(event.key) would admit those without letting a named key through.
Automated review (maintainer link)
<!-- codebunny-pub:1 k=0cec4223f298e42d664a42fa90272b1c267f74d446ce26ea9edf7c2e1c59594c -->
Approved these changes.
potatowagon
thorn0
Description
Typing after clicking a block decorator such as a divider produces no text in Firefox and WebKit because no native beforeinput reaches the editor. Handle printable keydown events for a single selected block decorator, preserving the first character and reusing an empty following block or inserting a paragraph before existing text.
Accept Option-generated printable characters on Apple platforms and retain the AltGraph path, including events that also report Control. Cancelled key events, Control/Command shortcuts, non-Apple Alt shortcuts, Space command listeners, embedded inputs, and native controls inside decorators retain their normal handling.
The beforeinput selection preparation runs only in the editor that originated the command, so a retained parent node selection cannot redirect a nested editor's insertion.
Tests cover native typing after a selected divider, empty and nonempty following blocks, button activation and select type-ahead, retained parent selections with native child-editor input, Apple-profile Option characters, shortcut controls, higher-priority listeners cancelling letters and Space while returning false, and browser-dispatched AltGraph events.
Changeset
Update the existing
.changeset/rich-text-type-after-selected-block-decorator.mdentry with Firefox/WebKit typing, cancellation, Option and AltGraph characters, embedded controls, and nested editors. Consolidate the duplicate pending entry into it.Test plan
Before
The original five native typing cases and shortcut control on unchanged upstream application source, before adding the initial-Space and control cases:
The same spec with
VITEST_BROWSER=webkitand--browser.headless=false:On b8bbbcdd with the two new native-control tests:
On 1acb5833 with the new Apple-profile Option and AltGraph unit cases:
Only the four Option-character cases failed; AltGraph and shortcut controls passed.
With only the beforeinput ownership guard removed, both nested-editor cases fail:
On 960b1add, all three native cancellation regressions fail:
The higher-priority listener runs, calls preventDefault(), and returns false. The fallback still inserts a new paragraph for a letter or Space.
After
Rich-text units:
Chromium and Firefox:
Linux GTK WebKit:
Source and test TypeScript checks, targeted ESLint/Prettier, changeset validation and git diff --check pass.
The Apple profile is mocked in unit tests. The AltGraph browser cases dispatch constructed KeyboardEvents; they do not emulate a physical keyboard layout. Real macOS Option/dead-key composition and native Safari were not tested locally.