mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Warn if undefined is passed to top-level render
Moved the top-level check to ReactChildFiber like the other ones
This commit is contained in:
@@ -1126,24 +1126,40 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
|
||||
}
|
||||
}
|
||||
|
||||
const Component = returnFiber.type;
|
||||
let validEmptyReturnType = newChild === null || newChild === false;
|
||||
|
||||
if (__DEV__) {
|
||||
if (!validEmptyReturnType &&
|
||||
returnFiber.tag === ClassComponent &&
|
||||
returnFiber.stateNode.render._isMockFunction) {
|
||||
// We allow auto-mocks to proceed as if they're returning null.
|
||||
validEmptyReturnType = true;
|
||||
if (returnFiber.tag === HostRoot) {
|
||||
// Top-level only accepts elements or portals
|
||||
invariant(
|
||||
false,
|
||||
'render(): Invalid component element.'
|
||||
);
|
||||
} else {
|
||||
switch (returnFiber.tag) {
|
||||
case ClassComponent: {
|
||||
if (__DEV__) {
|
||||
const instance = returnFiber.stateNode;
|
||||
if (instance.render._isMockFunction) {
|
||||
// We allow auto-mocks to proceed as if they're
|
||||
// returning null.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Intentionally fall through to the next case, which handles both
|
||||
// functions and classes
|
||||
// eslint-disable-next-lined no-fallthrough
|
||||
case FunctionalComponent: {
|
||||
// Composites accept elements, portals, null, or false
|
||||
const Component = returnFiber.type;
|
||||
invariant(
|
||||
newChild === null || newChild === false,
|
||||
'%s.render(): A valid React element (or null) must be ' +
|
||||
'returned. You may have returned undefined, an array or some ' +
|
||||
'other invalid object.',
|
||||
Component.displayName || Component.name || 'Component'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
invariant(
|
||||
validEmptyReturnType,
|
||||
'%s.render(): A valid React element (or null) must be returned. You ' +
|
||||
'may have returned undefined, an array or some other invalid object.',
|
||||
Component.displayName || Component.name || 'Component'
|
||||
);
|
||||
return deleteRemainingChildren(returnFiber, currentFirstChild);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,6 @@ import type { FiberRoot } from 'ReactFiberRoot';
|
||||
import type { PriorityLevel } from 'ReactPriorityLevel';
|
||||
import type { ReactNodeList } from 'ReactTypes';
|
||||
|
||||
var { isValidElement } = require('ReactElement');
|
||||
var invariant = require('invariant');
|
||||
var ReactFeatureFlags = require('ReactFeatureFlags');
|
||||
|
||||
var {
|
||||
addTopLevelUpdate,
|
||||
} = require('ReactFiberUpdateQueue');
|
||||
@@ -138,11 +134,6 @@ module.exports = function<T, P, I, TI, PI, C, CX>(config : HostConfig<T, P, I, T
|
||||
},
|
||||
|
||||
updateContainer(element : ReactNodeList, container : OpaqueNode, parentComponent : ?ReactComponent<any, any, any>, callback: ?Function) : void {
|
||||
invariant(
|
||||
!ReactFeatureFlags.disableNewFiberFeatures || isValidElement(element),
|
||||
'render(): Invalid component element.'
|
||||
);
|
||||
|
||||
// TODO: If this is a nested container, this won't be the root.
|
||||
const root : FiberRoot = (container.stateNode : any);
|
||||
const current = root.current;
|
||||
|
||||
Reference in New Issue
Block a user