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

Reword duplicate key warning #10148

Merged
merged 5 commits into from
Jul 12, 2017

Conversation

flarnie
Copy link
Contributor

@flarnie flarnie commented Jul 11, 2017

what is the change?:

  • Removes the now-inaccurate description of behavior around duplicate
    keys
  • Adds link to 'key' docs page
  • Changes tone to be more casual and friendly

Alternative wording idea;
'Encountered two children with the same key, ${key}
Child keys must be unique; using duplicate keys is not supported and
will cause unexpected behavior in some versions of React.
See https://fb.me/react-warning-keys for more information on how to
fix this.'

why make this change?:
Mainly this change was needed because in React 16, duplicate keys will
not cause omission of items with duplicate keys. All items will be
rendered. It could happen that in future versions of React we will have
different behavior though.

test plan:
yarn test

issue:
Wishlist item on #8854

**what is the change?:**
 - Removes the now-inaccurate description of behavior around duplicate
   keys
 - Adds link to 'key' docs page
 - Changes tone to be more casual and friendly

Alternative wording idea;
'Encountered two children with the same key, ${key}
Child keys must be unique; using duplicate keys is not supported and
will cause unexpected behavior in some versions of React.
See https://fb.me/react-warning-keys for more information on how to
fix this.'

**why make this change?:**
Mainly this change was needed because in React 16, duplicate keys will
not cause omission of items with duplicate keys. All items will be
rendered. It could happen that in future versions of React we will have
different behavior though.

**test plan:**
`yarn test`

**issue:**
Wishlist item on facebook#8854
@flarnie flarnie added this to the 16.0 milestone Jul 11, 2017
Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I'd say this is good. Maybe we could refine the message part from:

"If it happens - unlucky! To be honest it happens to all of us"

To be:

"The is a very common source of bugs that you may not realise to begin with. We highly recommend you keep using keys, but be mindful of duplications as they will likely cause inconsistencies in your application."

Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we workshop the new message a bit before merging? I like that the tone of the message is friendlier, but it reads a bit too informally for my taste.

My suggestion is something along the lines of:

Encountered two children with the same key. Keys should be unique so that components maintain their identity across updates. Duplicate keys can lead to confusing bugs — the behavior is unspecified and could change in a future version. See https://fb.me/react-warning-keys for more information.

@sophiebits
Copy link
Collaborator

sophiebits commented Jul 12, 2017

We highly recommend you add keys

To be clear, this is NOT the message you get when you forget to add a key at all. This message is when you have two identical (nonempty) keys. It is a lot rarer. I don't think we should advise adding keys here. It would be confusing.

I don't think the website link is helpful as-is. If we weren't planning to revise it, I would drop it.

I like Andrew's, or you might like my version which is a little more explicit about the behavior you'll see:

Encountered two children with the same key. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

@flarnie
Copy link
Contributor Author

flarnie commented Jul 12, 2017

Great - will update this. It would be nice to fix the docs so that they work for this but not needed atm.

**what is the change?:**
Another tweak to the wording of this error to make it more clear and
accurate.

**why make this change?:**
The previous tweak was too casual in tone and still not clear enough.

**test plan:**
`yarn test` and `REACT_DOM_JEST_USE_FIBER=1 yarn run test`

**issue:**
Wishlist item on facebook#8854
Copy link
Collaborator

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix my typo please? :p otherwise good.

'how to fix this.%s',
'`%s`. Keys should be unique so that components maintain their ' +
'identity across updates. Non-unique keys may cause children to ' +
'be duplicated and/or omitted in — the behavior is ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, my bad -- this shouldn't have "in"

@flarnie flarnie dismissed acdlite’s stale review July 12, 2017 19:18

because spicyj approved

flarnie added 2 commits July 12, 2017 12:28
**what is the change?:**
Fixed a typo in the updated message
@flarnie flarnie merged commit 3b43f31 into facebook:master Jul 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants