Skip to content

Fix/backspace linebreak slot boundary - #8900

Closed
sahiee-dev wants to merge 2 commits into
meta:mainfrom
sahiee-dev:fix/backspace-linebreak-slot-boundary
Closed

sahiee-dev wants to merge 2 commits into
meta:mainfrom
sahiee-dev:fix/backspace-linebreak-slot-boundary

Conversation

@sahiee-dev

Copy link
Copy Markdown
Contributor

Description

While looking into RangeSelection.deleteCharacter, I found an edge case in the logic that handles deletion when there is no text left in the current deletion direction.

The method first walks through the node next to the caret to see if there is anything special it should handle before falling back to the generic deletion behavior. That logic currently only accounts for ElementNode and DecoratorNode. Since LineBreakNode isn't handled, it simply falls through without any action.

After that comes the slot boundary guard. If the caret ends up on a slot value, the function exits immediately because slot content behaves like a virtual shadow root, and deletion shouldn't cross into the host's real DOM. The problem is that this guard only checks whether the caret is on a slot value, it doesn't verify whether there was still a node that could have been deleted first.

As a result, when a bare block slot value (such as the attribution line in a Pull Quote) ends with one or more line breaks, placing the caret at the end and pressing Backspace does nothing. The sibling-caret loop skips over the LineBreakNode, the boundary guard returns early, and nothing gets deleted. Repeated Backspace presses continue to be silent no-ops.

Fix: Add the missing LineBreakNode case to the sibling-caret loop, mirroring the existing DecoratorNode handling. This allows trailing line breaks to be removed before the slot boundary guard is reached, while keeping the existing slot-boundary protection intact.

Closes #8898

Test plan

Added a unit test in packages/lexical/src/__tests__/unit/LexicalSlot.test.ts:

  • backspace deletes trailing linebreaks in a bare block value one at a time (Bug: Backspace does not delete line breaks inserted into a slot #8898)
    Creates a bare block slot value ending with two trailing line breaks, performs Backspace twice, and verifies that the number of line breaks decreases from 2 → 1 → 0 while leaving the text content unchanged.

The new test reproduces the issue on the original code (the line break count remains at 2 after pressing Backspace) and passes with the fix applied.

I also ran the full Lexical core unit test suite (818 tests), and everything passed without regressions. Finally, I verified the behavior manually in the browser: repeated Backspace presses now remove one trailing line break at a time, normal character deletion behaves as expected, and the existing slot-boundary protection at the true start of the slot content still correctly prevents deletion across the boundary.

Before

Screen.Recording.2026-07-31.at.5.56.51.PM.mov

After

Screen.Recording.2026-07-31.at.5.56.09.PM.mov

deleteCharacter's sibling-caret exploration loop only handles
ElementNode and DecoratorNode origins; a LineBreakNode falls through
unhandled and reaches the trailing slot-edge boundary guard, which
bails out unconditionally whenever the anchor's node is a slot value,
without checking whether there is still content in the deletion
direction. The LineBreakNode is left in place and backspace becomes a
silent no-op. Add the missing case, mirroring the existing decorator
handling: remove the LineBreakNode directly instead of falling through.
…LineBreak

The meta#8898 backspace test used two insertLineBreak() calls to set up its
two-trailing-linebreak fixture, which depends on the unrelated meta#8897
insertNodes fix to produce a clean structure. Build the fixture directly
so this test doesn't depend on another unmerged fix.
@vercel

vercel Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 31, 2026 12:29pm
lexical-playground Ready Ready Preview Jul 31, 2026 12:29pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 31, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jul 31, 2026
@etrepum

etrepum commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

#8900 and #8899 touch the same code and solve similar problems, they should be a single PR. Having this as two PRs basically doubles the review overhead.

@sahiee-dev

Copy link
Copy Markdown
Contributor Author

Closing this in favor of #8899, which now covers both fixes. Makes sense, they touch the same function family and I found this bug while verifying the other one, so it's the same investigation really. Thanks for the flag.

@sahiee-dev sahiee-dev closed this Aug 1, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — adad3eec Deployed Jul 31, 2026 by vercel[bot]
Preview – lexical-playground — adad3eec Deployed Jul 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Backspace does not delete line breaks inserted into a slot

2 participants