mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Use multiple checks instead of forking the entire function
Easier to follow this way, and less chance the two paths will get out of sync.
This commit is contained in:
1 parent
645ad6d261
commit
ba1d3829bc
1 file changed
+65
-90
@@ -64,7 +64,6 @@ const {
|
||||
FunctionalComponent,
|
||||
ClassComponent,
|
||||
HostText,
|
||||
HostRoot,
|
||||
HostPortal,
|
||||
CoroutineComponent,
|
||||
YieldComponent,
|
||||
@@ -1103,10 +1102,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
|
||||
// not as a fragment. Nested arrays on the other hand will be treated as
|
||||
// fragment nodes. Recursion happens at the normal flow.
|
||||
|
||||
if (ReactFeatureFlags.disableNewFiberFeatures) {
|
||||
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
|
||||
|
||||
// Handle object types
|
||||
if (typeof newChild === 'object' && newChild !== null) {
|
||||
// Support only the subset of return types that Stack supports. Treat
|
||||
// everything else as empty, but log a warning.
|
||||
if (typeof newChild === 'object' && newChild !== null) {
|
||||
if (disableNewFiberFeatures) {
|
||||
switch (newChild.$$typeof) {
|
||||
case REACT_ELEMENT_TYPE:
|
||||
return placeSingleChild(reconcileSingleElement(
|
||||
@@ -1124,8 +1126,46 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
|
||||
priority
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (newChild.$$typeof) {
|
||||
case REACT_ELEMENT_TYPE:
|
||||
return placeSingleChild(reconcileSingleElement(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_COROUTINE_TYPE:
|
||||
return placeSingleChild(reconcileSingleCoroutine(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_YIELD_TYPE:
|
||||
return placeSingleChild(reconcileSingleYield(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_PORTAL_TYPE:
|
||||
return placeSingleChild(reconcileSinglePortal(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (disableNewFiberFeatures) {
|
||||
// The new child is not an element. If it's not null or false,
|
||||
// and the return fiber is a composite component, throw an error.
|
||||
switch (returnFiber.tag) {
|
||||
case ClassComponent: {
|
||||
if (__DEV__) {
|
||||
@@ -1152,35 +1192,6 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof newChild === 'string' || typeof newChild === 'number') {
|
||||
return placeSingleChild(reconcileSingleTextNode(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
'' + newChild,
|
||||
priority
|
||||
));
|
||||
}
|
||||
|
||||
if (isArray(newChild)) {
|
||||
return reconcileChildrenArray(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
|
||||
if (getIteratorFn(newChild)) {
|
||||
return reconcileChildrenIterator(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
|
||||
return deleteRemainingChildren(returnFiber, currentFirstChild);
|
||||
}
|
||||
|
||||
if (typeof newChild === 'string' || typeof newChild === 'number') {
|
||||
@@ -1192,69 +1203,33 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
|
||||
));
|
||||
}
|
||||
|
||||
if (typeof newChild === 'object' && newChild !== null) {
|
||||
switch (newChild.$$typeof) {
|
||||
case REACT_ELEMENT_TYPE:
|
||||
return placeSingleChild(reconcileSingleElement(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_COROUTINE_TYPE:
|
||||
return placeSingleChild(reconcileSingleCoroutine(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_YIELD_TYPE:
|
||||
return placeSingleChild(reconcileSingleYield(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
|
||||
case REACT_PORTAL_TYPE:
|
||||
return placeSingleChild(reconcileSinglePortal(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
));
|
||||
}
|
||||
|
||||
if (isArray(newChild)) {
|
||||
return reconcileChildrenArray(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
|
||||
if (getIteratorFn(newChild)) {
|
||||
return reconcileChildrenIterator(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
if (isArray(newChild)) {
|
||||
return reconcileChildrenArray(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof newChild === 'undefined') {
|
||||
if (getIteratorFn(newChild)) {
|
||||
return reconcileChildrenIterator(
|
||||
returnFiber,
|
||||
currentFirstChild,
|
||||
newChild,
|
||||
priority
|
||||
);
|
||||
}
|
||||
|
||||
if (!disableNewFiberFeatures && typeof newChild === 'undefined') {
|
||||
// If the new child is undefined, and the return fiber is a composite
|
||||
// component, throw an error. If Fiber return types are disabled,
|
||||
// we already threw above.
|
||||
switch (returnFiber.tag) {
|
||||
case HostRoot:
|
||||
// TODO: Top-level render
|
||||
break;
|
||||
case ClassComponent: {
|
||||
if (__DEV__) {
|
||||
const instance = returnFiber.stateNode;
|
||||
if (instance.render._isMockFunction && typeof newChild === 'undefined') {
|
||||
if (instance.render._isMockFunction) {
|
||||
// We allow auto-mocks to proceed as if they're returning null.
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user