Skip to content

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

Merged
sophiebits merged 2 commits into
react:masterfrom
ianobermiller:children-map-key-slash
Feb 11, 2016
Merged

ReactChildren.map: only add slash if new child has key#5892
sophiebits merged 2 commits into
react:masterfrom
ianobermiller:children-map-key-slash

Conversation

@ianobermiller

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

cc @spicyj

@ianobermiller
ianobermiller force-pushed the children-map-key-slash branch from 4111232 to 39410e7 Compare January 21, 2016 00:18
@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
Copy Markdown
Contributor

@ianobermiller updated the pull request.

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Nice catch, thanks.

@ianobermiller
ianobermiller force-pushed the children-map-key-slash branch from 39410e7 to 86bfc80 Compare January 21, 2016 03:01
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@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.
@ianobermiller
ianobermiller force-pushed the children-map-key-slash branch from 86bfc80 to 30f7641 Compare January 21, 2016 03:20

Copy link
Copy Markdown
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
Copy Markdown
Contributor

@ianobermiller updated the pull request.

@RoccoC

RoccoC commented Feb 11, 2016

Copy link
Copy Markdown

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 react:master Feb 11, 2016
@Erid

Erid commented Feb 11, 2016

Copy link
Copy Markdown

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

@jimfb

jimfb commented Feb 11, 2016

Copy link
Copy Markdown
Contributor

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

mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
ReactChildren.map: only add slash if new child has key
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