-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about unresolved function as a child #10376
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,16 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) { | |
} | ||
} | ||
|
||
function warnOnFunctionType() { | ||
warning( | ||
false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not pass in newChild and put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid two extra functions calls in DEV. (It's small but can add up.) Also I find our |
||
'Functions are not valid as a React child. This may happen if ' + | ||
'you return a Component instead of <Component /> from render. ' + | ||
'Or maybe you meant to call this function rather than return it.%s', | ||
getCurrentFiberStackAddendum() || '', | ||
); | ||
} | ||
|
||
// This wrapper function exists because I expect to clone the code in each path | ||
// to be able to optimize each path individually by branching early. This needs | ||
// a compiler or we can do it manually. Helpers that don't need this branching | ||
|
@@ -565,6 +575,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |
throwOnInvalidObjectType(returnFiber, newChild); | ||
} | ||
|
||
if (__DEV__) { | ||
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures; | ||
if (!disableNewFiberFeatures && typeof newChild === 'function') { | ||
warnOnFunctionType(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
@@ -638,6 +655,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |
throwOnInvalidObjectType(returnFiber, newChild); | ||
} | ||
|
||
if (__DEV__) { | ||
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures; | ||
if (!disableNewFiberFeatures && typeof newChild === 'function') { | ||
warnOnFunctionType(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
@@ -697,6 +721,13 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |
throwOnInvalidObjectType(returnFiber, newChild); | ||
} | ||
|
||
if (__DEV__) { | ||
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures; | ||
if (!disableNewFiberFeatures && typeof newChild === 'function') { | ||
warnOnFunctionType(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
@@ -1418,6 +1449,11 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |
throwOnInvalidObjectType(returnFiber, newChild); | ||
} | ||
|
||
if (__DEV__) { | ||
if (!disableNewFiberFeatures && typeof newChild === 'function') { | ||
warnOnFunctionType(); | ||
} | ||
} | ||
if (!disableNewFiberFeatures && typeof newChild === 'undefined') { | ||
// If the new child is undefined, and the return fiber is a composite | ||
// component, throw an error. If Fiber return types are disabled, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-f