Throw if undefined is returned from a composite component

This commit is contained in:
Andrew Clark
2017-01-11 17:51:27 -08:00
parent 86280187d7
commit 204d3dd703
@@ -61,8 +61,10 @@ const {
const isArray = Array.isArray;
const {
FunctionalComponent,
ClassComponent,
HostText,
HostRoot,
HostPortal,
CoroutineComponent,
YieldComponent,
@@ -1197,6 +1199,25 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}
}
if (typeof newChild === 'undefined') {
switch (returnFiber.tag) {
case HostRoot:
// TODO: Top-level render
break;
case ClassComponent:
case FunctionalComponent: {
const Component = returnFiber.type;
invariant(
false,
'%s: Nothing was returned from render. This usually means a ' +
'return statement is missing. Or, to render nothing, ' +
'return null.',
Component.displayName || Component.name || 'Component'
);
}
}
}
// Remaining cases are all treated as empty.
return deleteRemainingChildren(returnFiber, currentFirstChild);
}