Skip to content

Bug: Typing after deleting a root-level block decorator inserts a phantom blank paragraph #8685

@mayrang

Description

@mayrang

Lexical version: latest on playground.lexical.dev (also reproducible against current main)

Steps To Reproduce

  1. Open https://playground.lexical.dev/.
  2. Type /page break (or /equation) to insert a block decorator at the start of an empty editor. Lexical inserts a trailing paragraph after the decorator.
  3. Press Backspace once — the trailing paragraph is removed and the decorator becomes a NodeSelection.
  4. Press Backspace again — the decorator is removed; the editor is left with the original empty paragraph at root.
  5. Type any character.

example:

2026-06-12.9.11.56.mov

The current behavior

Step 5 produces a phantom blank line above the typed character. The original empty paragraph is left untouched and a brand-new paragraph is appended after it for the typed text.

Trace: at typing time the RangeSelection's anchor is { key: 'root', offset: 1, type: 'element' }. RangeSelection.insertText routes through $transferStartingElementPointToTextPoint, which lands on the placementNode === null + isRootNode(element) branch (packages/lexical/src/LexicalSelection.ts:295-302). That branch unconditionally appends $createParagraphNode().append(textNode) to root, so the empty paragraph already at root is left behind.

The expected behavior

The typed character should land in the existing empty paragraph (the natural caret target after the decorator delete), with no extra blank line.

Impact of fix

  • Affects every block decorator that root can host (PageBreak, Equation, HorizontalRule, custom Card / Figure decorators, …).
  • One-line guard in $transferStartingElementPointToTextPoint: when root's last child is an empty non-inline ElementNode, reuse it instead of appending a new paragraph. PR coming up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions