[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
Conversation
… 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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
|
Fails ci-check |
Contributor
Author
|
CI is green now — added the ElementNode type guard. |
etrepum
reviewed
Apr 12, 2026
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
createSelectionFromOffsetsresolves an offset to an inline node (e.g. a DecoratorNode), it used the raw cumulative offset value as the element selection offset. This causedIndexSizeError: There is no child at offset Nbecause 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:
After
Selection is created correctly using the node's child index within its parent.
Added the first unit tests for the
@lexical/offsetpackage, covering inline node selection at both start and end boundaries.All existing tests pass (2741 passed, 0 failed).