-
Notifications
You must be signed in to change notification settings - Fork 47k
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 if the included mixin is undefined #6158
Changes from all commits
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 |
---|---|---|
|
@@ -437,6 +437,21 @@ function validateMethodOverride(isAlreadyDefined, name) { | |
*/ | ||
function mixSpecIntoComponent(Constructor, spec) { | ||
if (!spec) { | ||
if (__DEV__) { | ||
var typeofSpec = typeof spec; | ||
var isMixinValid = typeofSpec === 'object' && spec !== null; | ||
|
||
warning( | ||
isMixinValid, | ||
'%s: You\'re attempting to include a mixin that is either null ' + | ||
'or not an object. Check the mixins included by the component, ' + | ||
'as well as any mixins they include themselves. ' + | ||
'Expected object but got %s.', | ||
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. As far as I can see, this will print 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. Yeah right. IMHO, I don't think there might be a case where an array will be included as mixin? The docs also has an example with a mixin being an object. Thoughts? 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. I mean that we should avoid confusing warnings even if turn up in edge cases. var type;
if (spec == null) {
type = '' + spec;
} else if (Array.isArray(spec)) {
type = 'array';
} else {
type = typeof spec;
} 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. As noted below, you’re right—we’ll never get into this block with arrays anyway so it doesn’t matter. I was wrong! |
||
Constructor.displayName || 'ReactClass', | ||
spec === null ? null : typeofSpec | ||
); | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
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.
@gaearon Since we have this condition, a mixin in case if is an array, will never get inside this block.
I feel if a mixin is an array, then its better we show a separate warning that says:
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.
Ah, I see. Never mind then, I retract my previous comment 👍