Skip to content

Commit

Permalink
Only run unmounting loop if there are any remaining children to unmou…
Browse files Browse the repository at this point in the history
…nt (+2 B) (#4199)
  • Loading branch information
andrewiggins committed Nov 8, 2023
1 parent 9aa4728 commit f269b62
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,16 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
// unmount DOM from the beginning of the oldChildren, we can adjust oldDom to
// point to the next child, which needs to be the first DOM node that won't be
// unmounted.
for (i = 0; i < oldChildrenLength; i++) {
oldVNode = oldChildren[i];
if (oldVNode != null && (oldVNode._flags & MATCHED) === 0) {
if (oldVNode._dom == newParentVNode._nextDom) {
newParentVNode._nextDom = getDomSibling(oldVNode);
}
if (remainingOldChildren) {
for (i = 0; i < oldChildrenLength; i++) {
oldVNode = oldChildren[i];
if (oldVNode != null && (oldVNode._flags & MATCHED) === 0) {
if (oldVNode._dom == newParentVNode._nextDom) {
newParentVNode._nextDom = getDomSibling(oldVNode);
}

unmount(oldVNode, oldVNode);
unmount(oldVNode, oldVNode);
}
}
}
}
Expand Down

0 comments on commit f269b62

Please sign in to comment.