Skip to content

Commit

Permalink
Merge isObject branches (#21226)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage committed Apr 9, 2021
1 parent d4cae99 commit 3971371
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
46 changes: 21 additions & 25 deletions packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,7 @@ function ChildReconciler(shouldTrackSideEffects) {
}

// Handle object types
const isObject = typeof newChild === 'object' && newChild !== null;

if (isObject) {
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
return placeSingleChild(
Expand Down Expand Up @@ -1266,6 +1264,26 @@ function ChildReconciler(shouldTrackSideEffects) {
);
}
}

if (isArray(newChild)) {
return reconcileChildrenArray(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (getIteratorFn(newChild)) {
return reconcileChildrenIterator(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

throwOnInvalidObjectType(returnFiber, newChild);
}

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

if (isArray(newChild)) {
return reconcileChildrenArray(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (getIteratorFn(newChild)) {
return reconcileChildrenIterator(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (isObject) {
throwOnInvalidObjectType(returnFiber, newChild);
}

if (__DEV__) {
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
Expand Down
46 changes: 21 additions & 25 deletions packages/react-reconciler/src/ReactChildFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,7 @@ function ChildReconciler(shouldTrackSideEffects) {
}

// Handle object types
const isObject = typeof newChild === 'object' && newChild !== null;

if (isObject) {
if (typeof newChild === 'object' && newChild !== null) {
switch (newChild.$$typeof) {
case REACT_ELEMENT_TYPE:
return placeSingleChild(
Expand Down Expand Up @@ -1266,6 +1264,26 @@ function ChildReconciler(shouldTrackSideEffects) {
);
}
}

if (isArray(newChild)) {
return reconcileChildrenArray(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (getIteratorFn(newChild)) {
return reconcileChildrenIterator(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

throwOnInvalidObjectType(returnFiber, newChild);
}

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

if (isArray(newChild)) {
return reconcileChildrenArray(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (getIteratorFn(newChild)) {
return reconcileChildrenIterator(
returnFiber,
currentFirstChild,
newChild,
lanes,
);
}

if (isObject) {
throwOnInvalidObjectType(returnFiber, newChild);
}

if (__DEV__) {
if (typeof newChild === 'function') {
warnOnFunctionType(returnFiber);
Expand Down

0 comments on commit 3971371

Please sign in to comment.