Skip to content

[lexical-list] Bug Fix: fix selection issue from list transform on linebreak - #8049

Merged
etrepum merged 4 commits into
meta:mainfrom
dizsmek:fix-list-insert-on-linebreak
Dec 26, 2025
Merged

etrepum merged 4 commits into
meta:mainfrom
dizsmek:fix-list-insert-on-linebreak

Conversation

@dizsmek

@dizsmek dizsmek commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

Description

Describe the changes in this pull request
Current behavior:
When a paragraph ends with a LineBreakNode and the cursor is positioned at the end,
Lexical creates an element-anchored selection with an offset pointing after the last child.
When this paragraph is converted to a list, Lexical's selection reconciliation automatically
maps the selection from the paragraph to the newly created ListNode, preserving the offset.
However, the ListNode only has 1 child (the ListItemNode), so any offset greater than 1
becomes invalid on the ListNode.

This causes:

  1. IndexSizeError in the console: "Failed to execute 'setBaseAndExtent' on 'Selection':
    There is no child at offset X"
  2. Incorrect cursor position - the selection state becomes corrupted

New behavior:
After a paragraph is replaced with a list structure, the fix checks if the selection
was automatically mapped to the ListNode. If so, it redirects the selection to anchor
to the ListItemNode instead, while preserving the original offset.

This works because the ListItemNode contains the same children as the original paragraph,
making the offset valid on the ListItemNode even though it would be invalid on the ListNode.

Closes #8046

Test plan

Before

Screen.Recording.2025-12-23.at.12.07.00.PM.mov

Insert relevant screenshots/recordings/automated-tests

After

Screen.Recording.2025-12-23.at.12.07.37.PM.mov

Insert relevant screenshots/recordings/automated-tests

@vercel

vercel Bot commented Dec 23, 2025 •

Copy link
Copy Markdown

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

Project Deployment Review Updated (UTC)
lexical Ready Ready Preview, Comment Dec 26, 2025 8:29pm
lexical-playground Ready Ready Preview, Comment Dec 26, 2025 8:29pm

@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 Dec 23, 2025

@etrepum etrepum left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically the getKey accessor is used instead of __key. It would also be a good idea to add a test to this PR to show that it fixes the issue.

@dizsmek

dizsmek commented Dec 24, 2025

Copy link
Copy Markdown
Contributor Author

@etrepum added a test and replaced __key.

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — bcd1eddf Deployed Dec 26, 2025 by vercel[bot]
Preview – lexical — bcd1eddf Deployed Dec 26, 2025 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: Selection issue from list transform on multi-line paragraph

2 participants