-
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
Add component stack info to key validation warnings #6799
Conversation
addenda.parentOrOwner || '', | ||
addenda.childOwner || '', | ||
addenda.url || '' | ||
addenda.url || '', |
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.
We shouldn't need these other addenda now since the stack should cover it. Can you remove the code for them? We still will want to dedupe the warnings based on owner though as we're currently doing.
@keyanzhang updated the pull request. |
if (__DEV__) { | ||
traverseAllChildren( | ||
nestedChildNodes, | ||
(childInsts, child, name) => instantiateChild( |
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.
I tried to put selfDebugID
as the first arg of instantiateChild
and to use instantiateChild.bind(null, selfDebugID)
here, but that means we need to call bind
as well in the production build. Do you think the current approach (arrowed currying, if that's a term) is acceptable? @spicyj
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.
Yeah, this seems fine to me. (I think calling it parentDebugID
might be a little clearer, but this is also oaky.)
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.
Hmm, I thought about this; self
is more clear to me since we are talking about the current component which happens to be the parent for the children here.
@keyanzhang updated the pull request. |
@keyanzhang updated the pull request. |
@@ -25,6 +25,9 @@ var ReactTransitionChildMapping = { | |||
if (!children) { | |||
return children; | |||
} | |||
// TODO: `flattenChildren` now takes an extra `selfDebugID` argument |
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.
@spicyj what's a good way to get and feed debugID
to flattenChildren
here? The only place that calls ReactTransitionChildMapping.getChildMapping
(syntactic sugar for flattenChildren
) is here: https://github.com/facebook/react/blob/master/src/addons/transitions/ReactTransitionGroup.js#L41. In other words, how do I/can I get a debugID from a component?
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.
Also, seems like the only other place we use flattenChildren
is in ReactMultiChild
and there's already a test for that in ReactMultiChild-test
. Interestingly, when ReactChildReconciler
finds duplicated keys, the error message talks about "flattenChildren" (which is also test covered in the new ReactChildReconciler-test
file).
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.
var internalInstance = ReactInstanceMap.get(this);
internalInstance._debugID
should work. Maybe someday we'll have a public API to get this that anyone could use but for now I think it's okay for us to get the internal instance for this here.
This PR should be ready for review. I refactored |
@keyanzhang updated the pull request. |
1 similar comment
@keyanzhang updated the pull request. |
@@ -192,11 +192,17 @@ var ReactComponentTreeDevtool = { | |||
|
|||
var currentOwner = ReactCurrentOwner.current; | |||
var id = currentOwner && currentOwner._debugID; | |||
|
|||
info += ReactComponentTreeDevtool.getStackAddendumByID(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.
Nice.
Did you change anything in ReactElementValidator other than adding the stack? It's hard to tell because the code moved around. |
(Also, pretty sure I meant to do needs-revision on this last time! Just a few more questions and I think we'll be good.) |
@keyanzhang updated the pull request. |
@@ -38,6 +39,7 @@ var ReactTransitionGroup = React.createClass({ | |||
|
|||
getInitialState: function() { | |||
return { | |||
// TODO: can we get useful debug information to show at this point? |
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.
Interestingly, ReactInstanceMap doesn't have information for the component at this point. That's probably because the component hasn't been mounted.
looks good to me, feel free to "squash and merge" |
Yay I am so stoked for this to be merged in! Great work react team! |
* Add component stack info to key validation warnings * Add `ReactComponentTreeDevtool.getStackAddendumByID` (cherry picked from commit 47e49ae)
* Add component stack info to key validation warnings * Add `ReactComponentTreeDevtool.getStackAddendumByID` (cherry picked from commit 47e49ae)
This PR implements #6790.
I rewrote some of the tests from JSX tocreateElement
calls since #6398 added source locations at JSX compile-time and hard-coding line numbers in tests doesn't sound good.ReactChildReconciler
flattenChildren
ReactElementValidator
ReactElementValidator-test
ReactChildReconciler-test
ReactMultiChild-test
ReactElementValidator
ReactElementValidator-test
ReactChildReconciler
flattenChildren
and add test casesReactComponentTreeDevtool.getStackAddendumByID
debugID
toReactTransitionChildMapping.getChildMapping
ReactElementValidator
Error Message -- Add both child and parent name to key-missing warning stack #6823