Skip to content

Commit fa1ba76

Browse files
committed
Fix edge case where oldChild can become detach causing the recursive function to end early
1 parent 0e48d10 commit fa1ba76

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/rrdom/src/diff.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,14 @@ function diffChildren(
527527
let oldChild = oldTree.firstChild;
528528
let newChild = newTree.firstChild;
529529
while (oldChild !== null && newChild !== null) {
530+
const { previousSibling } = oldChild;
530531
diff(oldChild, newChild, replayer, rrnodeMirror);
532+
533+
// If oldChild is detached from oldTree, use its previous sibling to prevent early termination of recursive diff.
534+
if (oldChild.parentNode !== oldTree && previousSibling) {
535+
oldChild = previousSibling
536+
}
537+
531538
oldChild = oldChild.nextSibling;
532539
newChild = newChild.nextSibling;
533540
}

0 commit comments

Comments
 (0)