Unset keys when concatenating child elements #640
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request seeks to modify the behavior of
wp.element.concatChildren
to unset keys instead of defining new keys by indices within the children and sets of children. Originally these keys were assigned to avoid conflict when a child shared the same key across the sets of children. The problem with this approach is that by only using the array indices, React may try to reconcile two elements from different sets of children that are not truly the same, but merely share the same index (e.g. key0,0
). Instead, we could either ensure a unique key every time we concatenate (via Lodash'suniqueId
) or as proposed here, simply unset the key. I had worried this might have produced a React warning recommending that keys be assigned, but in my testing, this does not appear to be the case.Testing instructions:
Ensure tests pass:
Verify that there is no regression in the behavior of merging text or heading blocks, and that in doing so, no warnings or errors are logged to your browser developer tools console.