Skip to content

Commit 8436691

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

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/rrdom/src/diff.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,15 @@ 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 grab the next sibling to continue diffing.
534+
if (oldChild.parentNode !== oldTree && previousSibling) {
535+
oldChild = previousSibling.nextSibling;
536+
continue;
537+
}
538+
531539
oldChild = oldChild.nextSibling;
532540
newChild = newChild.nextSibling;
533541
}

0 commit comments

Comments
 (0)