Fix ParentNode insertBefore linked-list corruption#610
Open
TrevorSundberg wants to merge 1 commit intoShopify:mainfrom
Open
Fix ParentNode insertBefore linked-list corruption#610TrevorSundberg wants to merge 1 commit intoShopify:mainfrom
TrevorSundberg wants to merge 1 commit intoShopify:mainfrom
Conversation
Author
|
I have signed the CLA! |
4256476 to
13ae5c3
Compare
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.
Summary
This fixes
ParentNode.insertInto()in@remote-dom/polyfillso inserting a child before a non-head reference node correctly links the previous sibling to the inserted child.The current implementation updates the inserted child and the reference node, but it does not update the previous sibling's
NEXTpointer whenbefore[PREV]is notnull. That leaves the sibling list internally inconsistent: the inserted node hasPREV/NEXTlinks, and the reference node points back to it, but traversal from the parent's first child skips the inserted node.Affected source:
https://github.com/Shopify/remote-dom/blob/main/packages/polyfill/source/ParentNode.ts#L120-L127
Before:
After:
Tests passed:
corepack pnpm type-check,corepack pnpm lint, andcorepack pnpm exec vitest run.Root Cause
For non-head insertions,
before[PREV]is the previous sibling. That sibling must have itsNEXTpointer changed to the inserted child. Without that update, the list can become inconsistent after DOM moves such as keyed reorders.This diverges from the normal DOM insertion invariant:
Instead, the current state can become: