-
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
ReactChildren.map: only add slash if new child has key #5892
ReactChildren.map: only add slash if new child has key #5892
Conversation
cc @spicyj |
4111232
to
39410e7
Compare
@ianobermiller updated the pull request. |
@@ -117,7 +117,7 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) { | |||
// traverseAllChildren used to do for objects as children | |||
keyPrefix + | |||
( | |||
mappedChild !== child ? | |||
mappedChild !== child && mappedChild.key ? | |||
escapeUserProvidedKey(mappedChild.key || '') + '/' : |
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.
Assume Ben likes this, can you drop the || ''
here since we already know we have it.
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.
Haven't thought about this in super detail yet but why not mappedChild.key !== child.key
as I suggested in chat?
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.
Yes, that makes sense, need to add a null-check then. Still need a truthy check on mappedChild.key
, so mappedChild.key && (!child || mappedChild.key !== child.key)
Nice catch, thanks. |
39410e7
to
86bfc80
Compare
@ianobermiller updated the pull request. |
See the new test for the scenario I am trying to fix; if you clone an element in React.cloneElement, vs just returning it directly, you will get a different key (with a slash in front) even though the two children are identical.
86bfc80
to
30f7641
Compare
@@ -117,8 +117,8 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) { | |||
// traverseAllChildren used to do for objects as children | |||
keyPrefix + | |||
( | |||
mappedChild !== child ? | |||
escapeUserProvidedKey(mappedChild.key || '') + '/' : | |||
(mappedChild.key && (!child || (child.key !== mappedChild.key))) ? |
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 hate all the parens, but this makes it crystal clear.
@ianobermiller updated the pull request. |
Curious if/when this PR will be merged into master? This PR will fix a few problems we are dealing with in our project. Thanks! |
ReactChildren.map: only add slash if new child has key
I'm unfamiliar with the process... When can we expect it to be published on npm? |
After the next release major release, which is probably less than a month away :). |
See the new test for the scenario I am trying to fix; if you clone an
element in React.cloneElement, vs just returning it directly, you will
get a different key (with a slash in front) even though the two
children are identical.
Test Plan:
npm test -- src/isomorphic/children/__tests__/ReactChildren-test.js