Skip to content
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 more detail to missing-key warning #6163

Closed
japgolly opened this issue Mar 2, 2016 · 7 comments
Closed

Add more detail to missing-key warning #6163

japgolly opened this issue Mar 2, 2016 · 7 comments

Comments

@japgolly
Copy link

japgolly commented Mar 2, 2016

I have a component in which I must be using an array and not setting keys because I get this warning:

Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of `Blah`.
See https://fb.me/react-warning-keys for more information.

The problem is that render methods aren't always simple and sometimes it's quite hard to find out where the problematic array is.

It would be awesome it the warning could be enhanced to provide some more information about the problematic dom. Something like:

Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of `Blah` when rendering: <ol><li>One</li><li>Two</li></ol>
See https://fb.me/react-warning-keys for more information.

or even

Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of `Blah`.
The head element renders to: <li>One</li>
See https://fb.me/react-warning-keys for more information.
@japgolly
Copy link
Author

japgolly commented Mar 2, 2016

The same goes for the flattenChildren(...): Encountered two children with the same key warning. Showing a subset of the DOM would be very, very helpful.

@troydemonbreun
Copy link
Contributor

Could you post a plunker or gist with the source example that contains the DOM to which you would want the above warnings to result?

@bpedersen
Copy link

I believe that a recreation of the issue would be in the following fiddle: https://jsfiddle.net/c8bxbjwv/.

You can see that both "hello" and "world" render, but the world is the invalid element as it doesn't have a key, but the error doesn't display that. I have created an attempt at fixing this with Pull Request #6317.

Please let me know your thoughts

@troydemonbreun
Copy link
Contributor

So, given that fiddle, what would the warning text be?

@bpedersen
Copy link

Currently I have a basic warning,

Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of 'Hello'. The head element renders to: <div>world<div/> See https://fb.me/react-warning-keys for more information.

We need to expand on it to cover edge cases, it currently isn't descriptive enough. For example if we have multiple divs with world as text it doesn't distinguish which one is the culprit.

@troydemonbreun
Copy link
Contributor

Cool, that would be helpful info.

@gaearon
Copy link
Collaborator

gaearon commented Jun 26, 2016

This was fixed in https://github.com/facebook/react/pull/6799—now we have an exact stack trace.

@gaearon gaearon closed this as completed Jun 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants