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.
This commit is contained in:
Andrew Clark committed 2017-02-02 12:05:00 -08:00
1 parent 02edc6bf18
commit ea2aa6e613
1 file changed
+13 -9
+13 -9
View File
@@ -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;
}
}
}