Skip to content

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

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

[lexical-list] Bug Fix: fix selection issue from list transform on linebreak#8049
etrepum merged 4 commits intofacebook:mainfrom
dizsmek:fix-list-insert-on-linebreak

Conversation

@dizsmek
Copy link
Copy Markdown
Contributor

@dizsmek dizsmek commented Dec 23, 2025

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
Copy link
Copy Markdown

vercel bot commented Dec 23, 2025

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
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

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
Copy link
Copy Markdown
Contributor Author

dizsmek commented Dec 24, 2025

@etrepum added a test and replaced __key.

@etrepum etrepum added this pull request to the merge queue Dec 26, 2025
Merged via the queue into facebook:main with commit 20e2c2f Dec 26, 2025
36 checks passed
@etrepum etrepum mentioned this pull request Jan 31, 2026
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