Skip to content

Commit 4e7e29b

Browse files
authored
Golf down children (#4485)
1 parent 1a6bd4d commit 4e7e29b

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/diff/children.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,7 @@ export function diffChildren(
6262

6363
for (i = 0; i < newChildrenLength; i++) {
6464
childVNode = newParentVNode._children[i];
65-
if (
66-
childVNode == null ||
67-
typeof childVNode == 'boolean' ||
68-
typeof childVNode == 'function'
69-
) {
70-
continue;
71-
}
65+
if (childVNode == null) continue;
7266

7367
// At this point, constructNewChildrenArray has assigned _index to be the
7468
// matchingIndex for this VNode's oldVNode (or -1 if there is no oldVNode).
@@ -185,6 +179,7 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
185179
typeof childVNode == 'function'
186180
) {
187181
childVNode = newParentVNode._children[i] = null;
182+
continue;
188183
}
189184
// If this newVNode is being reused (e.g. <div>{reuse}{reuse}</div>) in the same diff,
190185
// or we are rendering a component (e.g. setState) copy the oldVNodes so it can have
@@ -227,11 +222,6 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
227222
childVNode = newParentVNode._children[i] = childVNode;
228223
}
229224

230-
// Handle unmounting null placeholders, i.e. VNode => null in unkeyed children
231-
if (childVNode == null) {
232-
continue;
233-
}
234-
235225
const skewedIndex = i + skew;
236226
childVNode._parent = newParentVNode;
237227
childVNode._depth = newParentVNode._depth + 1;
@@ -299,9 +289,8 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
299289

300290
// Move this VNode's DOM if the original index (matchingIndex) doesn't
301291
// match the new skew index (i + new skew)
302-
if (matchingIndex !== i + skew) {
303-
childVNode._flags |= INSERT_VNODE;
304-
}
292+
// In the former two branches we know that it matches after skewing
293+
childVNode._flags |= INSERT_VNODE;
305294
}
306295
}
307296
}

0 commit comments

Comments
 (0)