-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Add component stack to invalid element type warning #8495
Conversation
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.
Thank you for sending this in! This looks pretty good to me. You'll need to rebase over #8612 if I land it soon.
I actually changed my mind a little bit on the stack – I think the "in Unknown" will be a little weird and I'm also a little uneasy about forcing the tree hook to understand invalid elements. Instead, can we change the "Check the render method of…" to be "Check your code at file.js:12." when a source is available for the element being created and then just use the stack for parent components?
'Warning: React.createElement: type should not be null, undefined, ' + | ||
'boolean, or number. It should be a string (for DOM elements) or a ' + | ||
'ReactClass (for composite components).' | ||
); | ||
// The format is ' in Unknown (at ReactElementValidator-test.js:539)' | ||
expectDev(lines[1]).toMatch( |
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.
Can you use normalizeCodeLocInfo like the other tests?
Wouldn't it be better to show "Check the render method of … (at file.js:12)" if we know the owner and show "Check your code at file.js:12." if we don't. It looks more useful to me in case I have many components in single file. What do you think? |
I think it's not necessary because the name will already be in the stack below, and in the case of "render callbacks" the current owner will often not be the "correct" component that is responsible. |
fa04ddf
to
1b3253f
Compare
Rebased and updated the code. Output:
Updated: Remove |
I’ll get this in for now and look at delimiting with newlines later for all warnings together. |
* Show Source Error Addemden if __source available * Add Parent Stack on invalid element type * refactor to use normalizeCodeLocInfo * Remove ( ) from addendum
To resolve #7856 and #7859 seems no longer active
Add stack addendum to Invalid element type warning
_source
(file and line number), the stack will be look likeIn Unknown (at file.js:12)
.element._source
). we will use parent's generated stack instead.Sample Code
Output (with babel transform)
Output (without _source from babel)
We drop the first line which is
in Unknown (created by Button)
since it's not very useful.