Skip to content

Commit f269b62

Browse files
authored
Only run unmounting loop if there are any remaining children to unmount (+2 B) (#4199)
1 parent 9aa4728 commit f269b62

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/diff/children.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,16 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
323323
// unmount DOM from the beginning of the oldChildren, we can adjust oldDom to
324324
// point to the next child, which needs to be the first DOM node that won't be
325325
// unmounted.
326-
for (i = 0; i < oldChildrenLength; i++) {
327-
oldVNode = oldChildren[i];
328-
if (oldVNode != null && (oldVNode._flags & MATCHED) === 0) {
329-
if (oldVNode._dom == newParentVNode._nextDom) {
330-
newParentVNode._nextDom = getDomSibling(oldVNode);
331-
}
326+
if (remainingOldChildren) {
327+
for (i = 0; i < oldChildrenLength; i++) {
328+
oldVNode = oldChildren[i];
329+
if (oldVNode != null && (oldVNode._flags & MATCHED) === 0) {
330+
if (oldVNode._dom == newParentVNode._nextDom) {
331+
newParentVNode._nextDom = getDomSibling(oldVNode);
332+
}
332333

333-
unmount(oldVNode, oldVNode);
334+
unmount(oldVNode, oldVNode);
335+
}
334336
}
335337
}
336338
}

0 commit comments

Comments
 (0)