Skip to content

Commit 9896fb7

Browse files
committed
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.
1 parent 645ad6d commit 9896fb7

File tree

1 file changed

+63
-87
lines changed

1 file changed

+63
-87
lines changed

src/renderers/shared/fiber/ReactChildFiber.js

Lines changed: 63 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11031103
// not as a fragment. Nested arrays on the other hand will be treated as
11041104
// fragment nodes. Recursion happens at the normal flow.
11051105

1106-
if (ReactFeatureFlags.disableNewFiberFeatures) {
1106+
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures;
1107+
1108+
// Handle object types
1109+
if (typeof newChild === 'object' && newChild !== null) {
11071110
// Support only the subset of return types that Stack supports. Treat
11081111
// everything else as empty, but log a warning.
1109-
if (typeof newChild === 'object' && newChild !== null) {
1112+
if (disableNewFiberFeatures) {
11101113
switch (newChild.$$typeof) {
11111114
case REACT_ELEMENT_TYPE:
11121115
return placeSingleChild(reconcileSingleElement(
@@ -1116,6 +1119,40 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11161119
priority
11171120
));
11181121

1122+
case REACT_PORTAL_TYPE:
1123+
return placeSingleChild(reconcileSinglePortal(
1124+
returnFiber,
1125+
currentFirstChild,
1126+
newChild,
1127+
priority
1128+
));
1129+
}
1130+
} else {
1131+
switch (newChild.$$typeof) {
1132+
case REACT_ELEMENT_TYPE:
1133+
return placeSingleChild(reconcileSingleElement(
1134+
returnFiber,
1135+
currentFirstChild,
1136+
newChild,
1137+
priority
1138+
));
1139+
1140+
case REACT_COROUTINE_TYPE:
1141+
return placeSingleChild(reconcileSingleCoroutine(
1142+
returnFiber,
1143+
currentFirstChild,
1144+
newChild,
1145+
priority
1146+
));
1147+
1148+
case REACT_YIELD_TYPE:
1149+
return placeSingleChild(reconcileSingleYield(
1150+
returnFiber,
1151+
currentFirstChild,
1152+
newChild,
1153+
priority
1154+
));
1155+
11191156
case REACT_PORTAL_TYPE:
11201157
return placeSingleChild(reconcileSinglePortal(
11211158
returnFiber,
@@ -1125,7 +1162,11 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11251162
));
11261163
}
11271164
}
1165+
}
11281166

1167+
if (disableNewFiberFeatures) {
1168+
// The new child is not an element. If it's not null or false,
1169+
// and the return fiber is a composite component, throw an error.
11291170
switch (returnFiber.tag) {
11301171
case ClassComponent: {
11311172
if (__DEV__) {
@@ -1152,35 +1193,6 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11521193
);
11531194
}
11541195
}
1155-
1156-
if (typeof newChild === 'string' || typeof newChild === 'number') {
1157-
return placeSingleChild(reconcileSingleTextNode(
1158-
returnFiber,
1159-
currentFirstChild,
1160-
'' + newChild,
1161-
priority
1162-
));
1163-
}
1164-
1165-
if (isArray(newChild)) {
1166-
return reconcileChildrenArray(
1167-
returnFiber,
1168-
currentFirstChild,
1169-
newChild,
1170-
priority
1171-
);
1172-
}
1173-
1174-
if (getIteratorFn(newChild)) {
1175-
return reconcileChildrenIterator(
1176-
returnFiber,
1177-
currentFirstChild,
1178-
newChild,
1179-
priority
1180-
);
1181-
}
1182-
1183-
return deleteRemainingChildren(returnFiber, currentFirstChild);
11841196
}
11851197

11861198
if (typeof newChild === 'string' || typeof newChild === 'number') {
@@ -1192,69 +1204,33 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11921204
));
11931205
}
11941206

1195-
if (typeof newChild === 'object' && newChild !== null) {
1196-
switch (newChild.$$typeof) {
1197-
case REACT_ELEMENT_TYPE:
1198-
return placeSingleChild(reconcileSingleElement(
1199-
returnFiber,
1200-
currentFirstChild,
1201-
newChild,
1202-
priority
1203-
));
1204-
1205-
case REACT_COROUTINE_TYPE:
1206-
return placeSingleChild(reconcileSingleCoroutine(
1207-
returnFiber,
1208-
currentFirstChild,
1209-
newChild,
1210-
priority
1211-
));
1212-
1213-
case REACT_YIELD_TYPE:
1214-
return placeSingleChild(reconcileSingleYield(
1215-
returnFiber,
1216-
currentFirstChild,
1217-
newChild,
1218-
priority
1219-
));
1220-
1221-
case REACT_PORTAL_TYPE:
1222-
return placeSingleChild(reconcileSinglePortal(
1223-
returnFiber,
1224-
currentFirstChild,
1225-
newChild,
1226-
priority
1227-
));
1228-
}
1229-
1230-
if (isArray(newChild)) {
1231-
return reconcileChildrenArray(
1232-
returnFiber,
1233-
currentFirstChild,
1234-
newChild,
1235-
priority
1236-
);
1237-
}
1207+
if (isArray(newChild)) {
1208+
return reconcileChildrenArray(
1209+
returnFiber,
1210+
currentFirstChild,
1211+
newChild,
1212+
priority
1213+
);
1214+
}
12381215

1239-
if (getIteratorFn(newChild)) {
1240-
return reconcileChildrenIterator(
1241-
returnFiber,
1242-
currentFirstChild,
1243-
newChild,
1244-
priority
1245-
);
1246-
}
1216+
if (getIteratorFn(newChild)) {
1217+
return reconcileChildrenIterator(
1218+
returnFiber,
1219+
currentFirstChild,
1220+
newChild,
1221+
priority
1222+
);
12471223
}
12481224

1249-
if (typeof newChild === 'undefined') {
1225+
if (!disableNewFiberFeatures && typeof newChild === 'undefined') {
1226+
// If the new child is undefined, and the return fiber is a composite
1227+
// component, throw an error. If Fiber return types are disabled,
1228+
// we already threw above.
12501229
switch (returnFiber.tag) {
1251-
case HostRoot:
1252-
// TODO: Top-level render
1253-
break;
12541230
case ClassComponent: {
12551231
if (__DEV__) {
12561232
const instance = returnFiber.stateNode;
1257-
if (instance.render._isMockFunction && typeof newChild === 'undefined') {
1233+
if (instance.render._isMockFunction) {
12581234
// We allow auto-mocks to proceed as if they're returning null.
12591235
break;
12601236
}

0 commit comments

Comments
 (0)