Skip to content

[lexical-offset] Bug Fix: Use child index instead of offset value for inline node selection#8312

Closed
Sathvik-Chowdary-Veerapaneni wants to merge 2 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:offset-inline-selection-7580
Closed

[lexical-offset] Bug Fix: Use child index instead of offset value for inline node selection#8312
Sathvik-Chowdary-Veerapaneni wants to merge 2 commits intofacebook:mainfrom
Sathvik-Chowdary-Veerapaneni:offset-inline-selection-7580

Conversation

@Sathvik-Chowdary-Veerapaneni
Copy link
Copy Markdown
Contributor

Description

When createSelectionFromOffsets resolves an offset to an inline node (e.g. a DecoratorNode), it used the raw cumulative offset value as the element selection offset. This caused IndexSizeError: There is no child at offset N because the parent element might only have 2-3 children while the offset value could be much larger.

Fixed by using the inline node's actual index within its parent (getIndexWithinParent()) instead of the raw offset value.

Closes #7580

Test plan

Before

Setting an offset that lands on an inline decorator node throws:

IndexSizeError: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 6.

After

Selection is created correctly using the node's child index within its parent.

Added the first unit tests for the @lexical/offset package, covering inline node selection at both start and end boundaries.

All existing tests pass (2741 passed, 0 failed).

… inline node selection

When createSelectionFromOffsets resolves an offset to an inline node
(e.g. a decorator), it used the raw offset value as the element
selection offset, causing "There is no child at offset N" errors.
Fixed by using the node's actual index within its parent.

Closes facebook#7580
@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 Apr 8, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 8, 2026

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 8, 2026 7:36pm
lexical-playground Ready Ready Preview, Comment Apr 8, 2026 7:36pm

Request Review

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Apr 8, 2026

Fails ci-check

@Sathvik-Chowdary-Veerapaneni
Copy link
Copy Markdown
Contributor Author

CI is green now — added the ElementNode type guard.

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.

I think the correct thing to do with this module is to deprecate OffsetView and $createOffsetView. There are no tests, or documentation for it and it's not used anywhere else in the lexical repo. The best thing to do is throw it out and start over with something that has well known behavior.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: @lexical/offset makes invalid selection if offset points to inline node

2 participants