Skip to content

Commit 204d3dd

Browse files
committed
Throw if undefined is returned from a composite component
1 parent 8628018 commit 204d3dd

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/renderers/shared/fiber/ReactChildFiber.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ const {
6161
const isArray = Array.isArray;
6262

6363
const {
64+
FunctionalComponent,
6465
ClassComponent,
6566
HostText,
67+
HostRoot,
6668
HostPortal,
6769
CoroutineComponent,
6870
YieldComponent,
@@ -1197,6 +1199,25 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
11971199
}
11981200
}
11991201

1202+
if (typeof newChild === 'undefined') {
1203+
switch (returnFiber.tag) {
1204+
case HostRoot:
1205+
// TODO: Top-level render
1206+
break;
1207+
case ClassComponent:
1208+
case FunctionalComponent: {
1209+
const Component = returnFiber.type;
1210+
invariant(
1211+
false,
1212+
'%s: Nothing was returned from render. This usually means a ' +
1213+
'return statement is missing. Or, to render nothing, ' +
1214+
'return null.',
1215+
Component.displayName || Component.name || 'Component'
1216+
);
1217+
}
1218+
}
1219+
}
1220+
12001221
// Remaining cases are all treated as empty.
12011222
return deleteRemainingChildren(returnFiber, currentFirstChild);
12021223
}

0 commit comments

Comments
 (0)