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

ReactChildren.map: only add slash if new child has key #5892

Merged
merged 2 commits into from
Feb 11, 2016

Conversation

ianobermiller
Copy link
Contributor

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

@ianobermiller
Copy link
Contributor Author

cc @spicyj

@ianobermiller ianobermiller changed the title Children map key slash ReactChildren.map: only add slash if new child has key Jan 21, 2016
@facebook-github-bot
Copy link

@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 || '') + '/' :
Copy link
Member

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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)

@ianobermiller
Copy link
Contributor Author

Nice catch, thanks.

@facebook-github-bot
Copy link

@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.
@@ -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))) ?
Copy link
Contributor Author

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.

@facebook-github-bot
Copy link

@ianobermiller updated the pull request.

@RoccoC
Copy link

RoccoC commented Feb 11, 2016

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!

sophiebits added a commit that referenced this pull request Feb 11, 2016
ReactChildren.map: only add slash if new child has key
@sophiebits sophiebits merged commit 3e41da7 into facebook:master Feb 11, 2016
@Erid
Copy link

Erid commented Feb 11, 2016

I'm unfamiliar with the process... When can we expect it to be published on npm?

@jimfb
Copy link
Contributor

jimfb commented Feb 11, 2016

After the next release major release, which is probably less than a month away :).

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.

7 participants