From f269b62c7a2a928fb8a120eeac49e715a7fc9500 Mon Sep 17 00:00:00 2001 From: Andre Wiggins <459878+andrewiggins@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:20:06 -0800 Subject: [PATCH] Only run unmounting loop if there are any remaining children to unmount (+2 B) (#4199) --- src/diff/children.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/diff/children.js b/src/diff/children.js index 0d3b704b51..97e42e9cc9 100644 --- a/src/diff/children.js +++ b/src/diff/children.js @@ -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); + } } } }