mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Throw if undefined is returned from a composite component
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user