-
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
Show component stack in PropTypes warnings #6771
Conversation
I had to track the stack because we don't know the parent hierarchy until the children are fully mounted. I wonder if we can change that. |
82cac57
to
397a15a
Compare
@spicyj updated the pull request. |
Can we add I think we should try harder to avoid relying on the stack again because this can become hard to rip out later. |
I think we don’t even need to pass it to the children as long as we set it right away after instantiating them but before recursing. |
397a15a
to
0d190f1
Compare
Yes, that works out nicely. How do you like this? |
@spicyj updated the pull request. |
👍 |
nextChild.parentID = id; | ||
} | ||
nextChild.parentID = id; | ||
// TODO: invariant(nextChild.parentID === id) makes sense but doesn't |
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 we add an invariant for the cases where we their parentId
is not missing? It being missing is just a subset of cases, is it not? I mean something like invariant(nextChild.parentID == null || nextChild.parentID === id)
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.
Yup, done.
0d190f1
to
fef1900
Compare
@spicyj updated the pull request. |
(cherry picked from commit 378c879)
(cherry picked from commit 378c879)
This works pretty well, even if you don't have source info compiled in – it falls back to annotating with owner info. The weirdest thing I noticed is that if A renders
<section><B /></section>
and B renders<div><C /></div>
and C gives a warning, then the stack will beand makes no mention of the div that should live between B and C: it can't, because that element hasn't been created yet. I think this probably won't be too confusing in practice but I wonder if there's something we can do to make it clearer.
cc @facebook/react-core