From ea2aa6e613b7009f5b3680057eb00d728c7333b1 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 2 Feb 2017 12:05:00 -0800 Subject: [PATCH] Fix messages so that they use the same template as Stack The production error code system depends on the exact template string that is passed to `invariant`. This changes the Fiber templates to match the Stack ones. --- src/renderers/shared/fiber/ReactChildFiber.js | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/renderers/shared/fiber/ReactChildFiber.js b/src/renderers/shared/fiber/ReactChildFiber.js index 646007ceff..bc0139c88f 100644 --- a/src/renderers/shared/fiber/ReactChildFiber.js +++ b/src/renderers/shared/fiber/ReactChildFiber.js @@ -1189,10 +1189,8 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { if (disableNewFiberFeatures) { // The new child is not an element. If it's not null or false, // and the return fiber is a composite component, throw an error. - let componentNameSuffix = '(...)'; switch (returnFiber.tag) { case ClassComponent: { - componentNameSuffix = '.render()'; if (__DEV__) { const instance = returnFiber.stateNode; if (instance.render._isMockFunction && typeof newChild === 'undefined') { @@ -1201,21 +1199,27 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { break; } } + 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', + ); + 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%s: A valid React element (or null) must be ' + - 'returned. You may have returned undefined, an array or some ' + - 'other invalid object.', + '%s(...): 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', - componentNameSuffix ); + break; } } }