← Back to Pull requests

[lexical-rich-text] Bug Fix: preserve typing after selected block decorators in Firefox and WebKit #9904

Merged
thorn0 merged 4 files (606 lines) on Nov 26, 2026 17:03 UTC
View on GitHub
thorn0 thorn0 commented on Nov 13, 2026 22:39 UTC
Author

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.md entry 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:

VITEST_BROWSER=chromium,firefox corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionTyping.test.ts --maxWorkers=1 --reporter=verbose

Test Files  1 failed | 1 passed (2)
     Tests  5 failed | 7 passed (12)

The same spec with VITEST_BROWSER=webkit and --browser.headless=false:

Test Files  1 failed (1)
     Tests  5 failed | 1 passed (6)

On b8bbbcdd with the two new native-control tests:

VITEST_BROWSER=chromium corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionTyping.test.ts --maxWorkers=1 --reporter=verbose -t 'leaves keyboard input in a selected decorator'

expected +0 to be 1 // Object.is equality
expected 'Apple' to be 'Quince' // Object.is equality
Test Files  1 failed (1)
     Tests  2 failed | 7 skipped (9)

On 1acb5833 with the new Apple-profile Option and AltGraph unit cases:

corepack pnpm exec vitest run --project=unit packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionTyping.test.ts --maxWorkers=1 --reporter=verbose

Test Files  1 failed (1)
     Tests  4 failed | 16 passed (20)

Only the four Option-character cases failed; AltGraph and shortcut controls passed.

With only the beforeinput ownership guard removed, both nested-editor cases fail:

VITEST_BROWSER=chromium corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionTyping.test.ts --maxWorkers=1 --reporter=json --outputFile=red.json -t 'leaves a nested editor'

Without ownership guard: 2 failed, 11 skipped
AssertionError: expected 'child' to be 'childq' // Object.is equality
AssertionError: expected 'child' to be 'child ' // Object.is equality

On 960b1add, all three native cancellation regressions fail:

VITEST_BROWSER=chromium corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser/RichTextNodeSelectionTyping.test.ts --maxWorkers=1 --reporter=json --outputFile=red.json -t 'honors a cancelled'

Tests: 3 failed, 0 passed, 13 skipped
AssertionError: expected { root: { children: [ …(4) ], …(7) } } to deeply equal { root: { children: [ …(3) ], …(7) } }

The higher-priority listener runs, calls preventDefault(), and returns false. The fallback still inserts a new paragraph for a letter or Space.

After

corepack pnpm exec vitest run --project=unit packages/lexical-rich-text/src/__tests__/unit --maxWorkers=1 --reporter=default
VITEST_BROWSER=chromium,firefox corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser --maxWorkers=1 --reporter=default
VITEST_BROWSER=webkit corepack pnpm exec vitest run --project=browser packages/lexical-rich-text/src/__tests__/browser --browser.headless=false --maxWorkers=1 --reporter=default

Rich-text units:

Test Files  21 passed (21)
     Tests  192 passed (192)

Chromium and Firefox:

Test Files  10 passed (10)
     Tests  96 passed (96)

Linux GTK WebKit:

Test Files  5 passed (5)
     Tests  48 passed (48)

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.

Diff: 606 lines (+574 / -32) across 4 files Reviewer: potatowagon Review duration: 18383m
All Vouch review confidence checks passed
Residual risk 0.12 = Change Risk (0.46) × (1 − Review Confidence (0.74)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 606 lines diff across 4 files
0.46
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.49 · 5 substantive comment(s)
0.49
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
73%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.383
Real PR Conversation Timeline
16 items
vercel[bot] vercel[bot] commented on Nov 13, 2026 22:39 UTC
Bot

[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>

rootnode-bot[bot] rootnode-bot[bot] commented on Nov 13, 2026 22:40 UTC
Bot

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 -->

pkg-pr-new[bot] pkg-pr-new[bot] commented on Nov 13, 2026 22:42 UTC
Bot

<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>_

rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 13, 2026 22:58 UTC
Code Review
packages/lexical-rich-text/src/index.ts:1
@@ -1294,6 +1321,24 @@ export function registerRichText(
     defaultShouldHandlePasteAsFiles,
   ),
 ): () => void {
+  const $insertTextAfterBlockDecorator = (event: KeyboardEvent): boolean => {
+    const selection = $getSelection();
+    // Firefox and WebKit need a DOM caret before they emit beforeinput.
+    if (
+      $isNodeSelection(selection) &&
+      event.key.length === 1 &&
+      !event.metaKey &&
+      ((!event.ctrlKey && !event.altKey) ||
+        event.getModifierState('AltGraph')) &&
+      !$isEventFromEmbeddedInput(event) &&

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) &&

rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 13, 2026 22:58 UTC
Code Review
packages/lexical-rich-text/src/index.ts:1
@@ -1294,6 +1321,24 @@ export function registerRichText(
     defaultShouldHandlePasteAsFiles,
   ),
 ): () => void {
+  const $insertTextAfterBlockDecorator = (event: KeyboardEvent): boolean => {
+    const selection = $getSelection();
+    // Firefox and WebKit need a DOM caret before they emit beforeinput.
+    if (
+      $isNodeSelection(selection) &&
+      event.key.length === 1 &&
+      !event.metaKey &&
+      ((!event.ctrlKey && !event.altKey) ||
+        event.getModifierState('AltGraph')) &&

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.

rootnode-bot[bot] rootnode-bot[bot] requested changes on Nov 13, 2026 22:58 UTC
Changes Requested Reviewer

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.

  • The default browser job runs Chromium only, and there the new spec passes even without the fix. A maintainer may want to add the 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 -->

    rootnode-bot[bot] rootnode-bot[bot] approved these changes on Nov 15, 2026 23:06 UTC
    Approved Reviewer

    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 -->

    rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 16, 2026 00:07 UTC
    Code Review
    packages/lexical-rich-text/src/index.ts:1
    @@ -1294,6 +1323,25 @@ export function registerRichText(
         defaultShouldHandlePasteAsFiles,
       ),
     ): () => void {
    +  const $insertTextAfterBlockDecorator = (event: KeyboardEvent): boolean => {
    +    const selection = $getSelection();
    +    // Firefox and WebKit need a DOM caret before they emit beforeinput.
    +    if (
    +      $isNodeSelection(selection) &&

    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 &&
    

    rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 16, 2026 00:07 UTC
    Code Review
    packages/lexical-rich-text/src/index.ts:1
    @@ -1294,6 +1323,25 @@ export function registerRichText(
         defaultShouldHandlePasteAsFiles,
       ),
     ): () => void {
    +  const $insertTextAfterBlockDecorator = (event: KeyboardEvent): boolean => {
    +    const selection = $getSelection();
    +    // Firefox and WebKit need a DOM caret before they emit beforeinput.
    +    if (
    +      $isNodeSelection(selection) &&
    +      event.key.length === 1 &&

    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.

    rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 16, 2026 00:07 UTC
    Code Review
    packages/lexical-rich-text/src/__tests__/unit/RichTextNodeSelectionTyping.test.ts:1
    @@ -91,6 +115,132 @@ function texts(editor: LexicalEditor): string[] {
     }
     
     describe('typing while a block decorator is node-selected', () => {
    +  test.for(['å', '©', 'ą', 'Å'])(

    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.

    rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 16, 2026 00:07 UTC
    Code Review
    .changeset/selected-block-keyboard-typing.md:1
    @@ -0,0 +1,7 @@
    +---
    +'@lexical/rich-text': patch
    +---
    +
    +[fix] Keep the first character typed after a selected block decorator in Firefox and WebKit

    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
    

    rootnode-bot[bot] rootnode-bot[bot] approved these changes on Nov 16, 2026 00:07 UTC
    Approved Reviewer

    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 -->

    rootnode-bot[bot] rootnode-bot[bot] commented on code on Nov 16, 2026 01:00 UTC
    Code Review
    packages/lexical-rich-text/src/index.ts:1
    @@ -1457,40 +1506,25 @@ export function registerRichText(
         ),
         editor.registerCommand(
           BEFORE_INPUT_COMMAND,
    -      event => {
    +      (event, fromEditor) => {
    +        // Preparing a parent caret would redirect a nested editor's insertion.
    +        if (fromEditor !== editor) {
    +          return false;
    +        }
             const selection = $getSelection();
    -        // A node selection has no DOM caret, so the browser would put typed
    -        // text at the top of the document. Move the caret into a line of its
    -        // own right after the decorator (an empty block already there, such
    -        // as the empty heading inserting a rule after a heading leaves, or a
    -        // new paragraph) and let the default handler take it from there: the
    -        // text does not join the start of the block after it.
             if ($isNodeSelection(selection) && event.inputType === 'insertText') {
    -          const nodes = selection.getNodes();
    -          if (
    -            nodes.length === 1 &&
    -            $isDecoratorNode(nodes[0]) &&
    -            !nodes[0].isInline()
    -          ) {
    -            const next = nodes[0].getNextSibling();
    -            if (
    -              $isElementNode(next) &&
    -              !next.isInline() &&
    -              next.isEmpty() &&
    -              next.canBeEmpty()
    -            ) {
    -              next.select();
    -            } else {
    -              const paragraph = $createParagraphNode();
    -              nodes[0].insertAfter(paragraph);
    -              paragraph.select();
    -            }
    -          }
    +          $selectAfterBlockDecorator(selection);
             }
             return false;
           },
           COMMAND_PRIORITY_LOW,
         ),
    +    editor.registerCommand(
    +      KEY_DOWN_COMMAND,
    +      // Space goes through KEY_SPACE_COMMAND so its listeners run first.
    +      event => event.key !== ' ' && $insertTextAfterBlockDecorator(event),

    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);
    

    rootnode-bot[bot] rootnode-bot[bot] approved these changes on Nov 16, 2026 01:00 UTC
    Approved Reviewer

    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 -->

    potatowagon potatowagon approved these changes on Nov 26, 2026 16:40 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    thorn0 thorn0
    Labels
    risk: low confidence: 73.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 73.5% · Lower = rushed or shallow review
    73.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.1% · Safe to merge
    12.1%
    Repository