Skip to content

Bug: Selection issue from list transform on multi-line paragraph #8046

@dizsmek

Description

@dizsmek

Lexical version: 0.39.0

Steps To Reproduce

  1. In a blank editor, enter a line of text, then insert a linebreak with Cmd + Shift
  2. Transform the paragraph into a list (ordered or unordered)
  3. Previously, the selection was on the linebreak, after transforming it into a list, the selection is on the list node itself. We also receive this console warning: IndexSizeError: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 2.

Link to code example:
This can be reproduced on the Lexical playground. It doesn't make sense to create a codesandbox for this, as it needs to be reproduced step by step. Here's a screen recording of how to reproduce it.

Screen.Recording.2025-12-22.at.10.45.04.AM.mov

The current behavior

After transforming a paragraph ending in a linebreak node into a list, we get the following console warning: IndexSizeError: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 2.

Additionally, our selection is set to the list node, as opposed to the linebreak node where we left our selection state before the transformation.

The expected behavior

Expected behavior is that we don't get the console warning, and our selection state is preserved, on the linebreak node.

Impact of fix

  • This bug affects a few live customers of an app using Lexical.
  • If focus is preserved on list transformation, this issue is more noticeable. If the editor is refocused after the transformation, the cursor jumps from the position of the linebreak node, up to the beginning of the list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    listsRelates to Lexical Lists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions