Skip to content

Commit 3971371

Browse files
authored
Merge isObject branches (#21226)
We assume that isArray and getIteratorFn are only called on objects. So we shouldn't have to check that again and again, and then check a flag. We can just stay in this branch. There is a slight semantic breakage here because you could have an iterator on a function, such as if it's a generator function. But that's not supported and that currently only works at the root. The inner slots don't support this. So this just makes it consistent.
1 parent d4cae99 commit 3971371

File tree

2 files changed

+42
-50
lines changed

2 files changed

+42
-50
lines changed

packages/react-reconciler/src/ReactChildFiber.new.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,7 @@ function ChildReconciler(shouldTrackSideEffects) {
12311231
}
12321232

12331233
// Handle object types
1234-
const isObject = typeof newChild === 'object' && newChild !== null;
1235-
1236-
if (isObject) {
1234+
if (typeof newChild === 'object' && newChild !== null) {
12371235
switch (newChild.$$typeof) {
12381236
case REACT_ELEMENT_TYPE:
12391237
return placeSingleChild(
@@ -1266,6 +1264,26 @@ function ChildReconciler(shouldTrackSideEffects) {
12661264
);
12671265
}
12681266
}
1267+
1268+
if (isArray(newChild)) {
1269+
return reconcileChildrenArray(
1270+
returnFiber,
1271+
currentFirstChild,
1272+
newChild,
1273+
lanes,
1274+
);
1275+
}
1276+
1277+
if (getIteratorFn(newChild)) {
1278+
return reconcileChildrenIterator(
1279+
returnFiber,
1280+
currentFirstChild,
1281+
newChild,
1282+
lanes,
1283+
);
1284+
}
1285+
1286+
throwOnInvalidObjectType(returnFiber, newChild);
12691287
}
12701288

12711289
if (typeof newChild === 'string' || typeof newChild === 'number') {
@@ -1279,28 +1297,6 @@ function ChildReconciler(shouldTrackSideEffects) {
12791297
);
12801298
}
12811299

1282-
if (isArray(newChild)) {
1283-
return reconcileChildrenArray(
1284-
returnFiber,
1285-
currentFirstChild,
1286-
newChild,
1287-
lanes,
1288-
);
1289-
}
1290-
1291-
if (getIteratorFn(newChild)) {
1292-
return reconcileChildrenIterator(
1293-
returnFiber,
1294-
currentFirstChild,
1295-
newChild,
1296-
lanes,
1297-
);
1298-
}
1299-
1300-
if (isObject) {
1301-
throwOnInvalidObjectType(returnFiber, newChild);
1302-
}
1303-
13041300
if (__DEV__) {
13051301
if (typeof newChild === 'function') {
13061302
warnOnFunctionType(returnFiber);

packages/react-reconciler/src/ReactChildFiber.old.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,7 @@ function ChildReconciler(shouldTrackSideEffects) {
12311231
}
12321232

12331233
// Handle object types
1234-
const isObject = typeof newChild === 'object' && newChild !== null;
1235-
1236-
if (isObject) {
1234+
if (typeof newChild === 'object' && newChild !== null) {
12371235
switch (newChild.$$typeof) {
12381236
case REACT_ELEMENT_TYPE:
12391237
return placeSingleChild(
@@ -1266,6 +1264,26 @@ function ChildReconciler(shouldTrackSideEffects) {
12661264
);
12671265
}
12681266
}
1267+
1268+
if (isArray(newChild)) {
1269+
return reconcileChildrenArray(
1270+
returnFiber,
1271+
currentFirstChild,
1272+
newChild,
1273+
lanes,
1274+
);
1275+
}
1276+
1277+
if (getIteratorFn(newChild)) {
1278+
return reconcileChildrenIterator(
1279+
returnFiber,
1280+
currentFirstChild,
1281+
newChild,
1282+
lanes,
1283+
);
1284+
}
1285+
1286+
throwOnInvalidObjectType(returnFiber, newChild);
12691287
}
12701288

12711289
if (typeof newChild === 'string' || typeof newChild === 'number') {
@@ -1279,28 +1297,6 @@ function ChildReconciler(shouldTrackSideEffects) {
12791297
);
12801298
}
12811299

1282-
if (isArray(newChild)) {
1283-
return reconcileChildrenArray(
1284-
returnFiber,
1285-
currentFirstChild,
1286-
newChild,
1287-
lanes,
1288-
);
1289-
}
1290-
1291-
if (getIteratorFn(newChild)) {
1292-
return reconcileChildrenIterator(
1293-
returnFiber,
1294-
currentFirstChild,
1295-
newChild,
1296-
lanes,
1297-
);
1298-
}
1299-
1300-
if (isObject) {
1301-
throwOnInvalidObjectType(returnFiber, newChild);
1302-
}
1303-
13041300
if (__DEV__) {
13051301
if (typeof newChild === 'function') {
13061302
warnOnFunctionType(returnFiber);

0 commit comments

Comments
 (0)