diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index 6fab354c4e..acaaff8725 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -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); } diff --git a/src/renderers/shared/fiber/ReactFiberReconciler.js b/src/renderers/shared/fiber/ReactFiberReconciler.js index d74d16226f..52cc90f57d 100644 --- a/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -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(config : HostConfig, 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;