-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Fix key
Warning for Flattened Positional Children
#29662
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -953,7 +953,7 @@ export function createElement(type, config, children) { | |
} | ||
|
||
export function cloneAndReplaceKey(oldElement, newKey) { | ||
return ReactElement( | ||
const clonedElement = ReactElement( | ||
oldElement.type, | ||
newKey, | ||
// When enableRefAsProp is on, this argument is ignored. This check only | ||
|
@@ -966,6 +966,11 @@ export function cloneAndReplaceKey(oldElement, newKey) { | |
__DEV__ && enableOwnerStacks ? oldElement._debugStack : undefined, | ||
__DEV__ && enableOwnerStacks ? oldElement._debugTask : undefined, | ||
); | ||
if (__DEV__) { | ||
// The cloned element should inherit the original element's key validation. | ||
clonedElement._store.validated = oldElement._store.validated; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that, too. I don't think it's necessary because we always define it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the other call sites check for But here, we are creating |
||
} | ||
return clonedElement; | ||
} | ||
|
||
/** | ||
|
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.
Maybe add another example where it does still correctly warn if an array was used without keys?
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.
we should have test for this already
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.
Surprisingly, we don't for the simple case. (We do for iterables of children.)