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

Reword duplicate key warning #10148

Merged
merged 5 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/isomorphic/children/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ function flattenSingleChildIntoContext(
warning(
false,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
'`%s`. There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.%s',
unescapeInDev(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID),
);
Expand Down
26 changes: 18 additions & 8 deletions src/renderers/__tests__/ReactChildReconciler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ describe('ReactChildReconciler', () => {

expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Child keys must be unique; when two children share a key, only the first child will be used.',
'There is a possibility that maybe your app will break due to you ' +
'using keys this way. If it happens – unlucky! To be honest it ' +
'happens to all of us. See https://fb.me/react-warning-keys for ' +
'more information on how to fix this.',
);
});

Expand Down Expand Up @@ -92,9 +95,11 @@ describe('ReactChildReconciler', () => {
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
).toContain(
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
'only the first child will be used.\n' +
' in div (at **)\n' +
'There is a possibility that maybe your app will break due to you ' +
'using keys this way. If it happens – unlucky! To be honest it ' +
'happens to all of us. See https://fb.me/react-warning-keys for ' +
'more information on how to fix this.',
' in div (at **)\n' +
' in Component (at **)\n' +
' in Parent (at **)\n' +
' in GrandParent (at **)',
Expand All @@ -114,7 +119,10 @@ describe('ReactChildReconciler', () => {

expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Child keys must be unique; when two children share a key, only the first child will be used.',
'There is a possibility that maybe your app will break due to you ' +
'using keys this way. If it happens – unlucky! To be honest it ' +
'happens to all of us. See https://fb.me/react-warning-keys for ' +
'more information on how to fix this.',
);
});

Expand Down Expand Up @@ -146,9 +154,11 @@ describe('ReactChildReconciler', () => {
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
).toContain(
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
'only the first child will be used.\n' +
' in div (at **)\n' +
'There is a possibility that maybe your app will break due to you ' +
'using keys this way. If it happens – unlucky! To be honest it ' +
'happens to all of us. See https://fb.me/react-warning-keys for ' +
'more information on how to fix this.',
' in div (at **)\n' +
' in Component (at **)\n' +
' in Parent (at **)\n' +
' in GrandParent (at **)',
Expand Down
18 changes: 12 additions & 6 deletions src/renderers/__tests__/ReactMultiChild-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ describe('ReactMultiChild', () => {
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
).toContain(
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
'only the first child will be used.\n' +
' in div (at **)\n' +
'There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.',
' in div (at **)\n' +
' in WrapperComponent (at **)\n' +
' in div (at **)\n' +
' in Parent (at **)',
Expand Down Expand Up @@ -254,9 +257,12 @@ describe('ReactMultiChild', () => {
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
).toContain(
'Encountered two children with the same key, `1`. ' +
'Child keys must be unique; when two children share a key, ' +
'only the first child will be used.\n' +
' in div (at **)\n' +
'There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.',
' in div (at **)\n' +
' in WrapperComponent (at **)\n' +
' in div (at **)\n' +
' in Parent (at **)',
Expand Down
9 changes: 6 additions & 3 deletions src/renderers/shared/fiber/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,12 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}
warning(
false,
'Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, ' +
'only the first child will be used.%s',
'Encountered two children with the same key, `%s`. ' +
'There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.%s',
key,
getCurrentFiberStackAddendum(),
);
Expand Down
10 changes: 7 additions & 3 deletions src/renderers/shared/stack/reconciler/ReactChildReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ function instantiateChild(childInstances, child, name, selfDebugID) {
if (!keyUnique) {
warning(
false,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
'flattenChildren(...):' +
'Encountered two children with the same key, `%s`. ' +
'There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.%s',
KeyEscapeUtils.unescapeInDev(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID),
);
Expand Down
7 changes: 5 additions & 2 deletions src/renderers/shared/stack/reconciler/flattenStackChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ function flattenSingleChildIntoContext(
warning(
false,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
'`%s`. There is a possibility that maybe your app will break due ' +
'to you using keys this way. If it happens – unlucky!' +
' To be honest it happens to all of us. ' +
'See https://fb.me/react-warning-keys for more information on ' +
'how to fix this.%s',
KeyEscapeUtils.unescapeInDev(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID),
);
Expand Down