Repository navigation
[lexical] Bug Fix: don't create a sibling cycle when splice re-inserts the node after the range - #8916
Merged
Conversation
…s the node after the range
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 4, 2026 06:54
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Aug 5, 2026
Merged
This branch was successfully deployed
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
ElementNode.splice()capturesnodeAfterRangebefore mutating and uses it at the end to re-link the tail of the range. The insert loop already handles the case where a node being inserted isprevNode, but not the case where it isnodeAfterRange. When that happens the node ends up asprevNodetoo, and the tail fix-up setsnode.__prev = node.__keyandnode.__next = node.__key— a self-referencing sibling link.Any children walk then never terminates:
getChildren(),getChildrenKeys(),getNextSibling()loops, and the reconciler all spin until the process dies withRangeError: Invalid array length.Two ordinary calls reproduce it:
parent.splice(1, 0, [parent.getChildAtIndex(1)])— a no-op re-insertparent.splice(1, 1, [laterSibling])— delete one child and move a later sibling into its placespliceis public API and is also reached via the caret API —ChildCaretFirst.insert()callsorigin.splice(0, 0, [node]).The fix mirrors the existing
prevNodeguard: advancenodeAfterRangepast a node that is being re-inserted. The tail branch is keyed offnodeAfterRange === nullinstead ofstart + deleteCount === oldSize— equivalent when no re-insert happens, and correct when the advance runs off the end so__lastis still fixed up.Test plan
Before
Two new tests in the existing
splicedescribe fail, showing a node whose__nextand__prevboth equal its own__key:Both assertions live inside the same
editor.update()as thesplice, with the sibling-pointer check first — so onmainthe test fails fast with a readable message instead of hanging, and the aborted update discards the corrupt pending state rather than handing it to the reconciler. With that fast assertion removed, the same tests instead spin for ~21s and die withRangeError: Invalid array lengthinsidegetChildrenKeys, which is the real-world symptom.After
Sibling links,
getChildrenKeys(),getChildrenSize(),getLastChild()andgetTextContent()all correct. Full unit suite green (227 files, 4940 passed).