Simplify wording of key warning (#14503)
I don't think "array or iterator" is adding anything, and it may well be confusing, especially since this is one of the first and most common warnings that devs see.
Sophie Alpert committed
Jan 7, 2019 at 08:30 UTC
547e059f0bc88e76cd738b01b76e777ff1b222a7
9 files changed
+23
-31
packages/react-dom/src/__tests__/ReactFunctionComponent-test.js
+1
-1
@@ -354,7 +354,7 @@ describe('ReactFunctionComponent', () => {
354
}
355
356
expect(() => ReactTestUtils.renderIntoDocument(<Child />)).toWarnDev(
357
- 'Each child in an array or iterator should have a unique "key" prop.\n\n' +
357
+ 'Each child in a list should have a unique "key" prop.\n\n' +
358
'Check the render method of `Child`.',
359
);
360
});
packages/react-dom/src/__tests__/ReactMultiChildText-test.js
+2
-2
@@ -162,8 +162,8 @@ describe('ReactMultiChildText', () => {
162
['', 'foo', <div>{true}{<div />}{1.2}{''}</div>, 'foo'], ['', 'foo', <div />, 'foo'],
163
]);
164
}).toWarnDev([
165
- 'Warning: Each child in an array or iterator should have a unique "key" prop.',
166
- 'Warning: Each child in an array or iterator should have a unique "key" prop.',
165
+ 'Warning: Each child in a list should have a unique "key" prop.',
166
+ 'Warning: Each child in a list should have a unique "key" prop.',
167
]);
168
});
169
packages/react-reconciler/src/ReactChildFiber.js
+2
-2
@@ -80,7 +80,7 @@ if (__DEV__) {
80
child._store.validated = true;
81
82
const currentComponentErrorInfo =
83
- 'Each child in an array or iterator should have a unique ' +
83
+ 'Each child in a list should have a unique ' +
84
'"key" prop. See https://fb.me/react-warning-keys for ' +
85
'more information.' +
86
getCurrentFiberStackInDev();
@@ -91,7 +91,7 @@ if (__DEV__) {
91
92
warning(
93
false,
94
- 'Each child in an array or iterator should have a unique ' +
94
+ 'Each child in a list should have a unique ' +
95
'"key" prop. See https://fb.me/react-warning-keys for ' +
96
'more information.',
97
);
packages/react-reconciler/src/__tests__/ReactFragment-test.js
+4
-4
@@ -709,7 +709,7 @@ describe('ReactFragment', () => {
709
710
ReactNoop.render(<Foo condition={false} />);
711
expect(ReactNoop.flush).toWarnDev(
712
- 'Each child in an array or iterator should have a unique "key" prop.',
712
+ 'Each child in a list should have a unique "key" prop.',
713
);
714
715
expect(ops).toEqual([]);
@@ -753,12 +753,12 @@ describe('ReactFragment', () => {
753
754
ReactNoop.render(<Foo condition={true} />);
755
expect(ReactNoop.flush).toWarnDev(
756
- 'Each child in an array or iterator should have a unique "key" prop.',
756
+ 'Each child in a list should have a unique "key" prop.',
757
);
758
759
ReactNoop.render(<Foo condition={false} />);
760
expect(ReactNoop.flush).toWarnDev(
761
- 'Each child in an array or iterator should have a unique "key" prop.',
761
+ 'Each child in a list should have a unique "key" prop.',
762
);
763
764
expect(ops).toEqual(['Update Stateful']);
@@ -766,7 +766,7 @@ describe('ReactFragment', () => {
766
767
ReactNoop.render(<Foo condition={true} />);
768
expect(ReactNoop.flush).toWarnDev(
769
- 'Each child in an array or iterator should have a unique "key" prop.',
769
+ 'Each child in a list should have a unique "key" prop.',
770
);
771
772
expect(ops).toEqual(['Update Stateful', 'Update Stateful']);
packages/react/src/ReactElementValidator.js
+1
-1
@@ -126,7 +126,7 @@ function validateExplicitKey(element, parentType) {
126
if (__DEV__) {
127
warning(
128
false,
129
- 'Each child in an array or iterator should have a unique "key" prop.' +
129
+ 'Each child in a list should have a unique "key" prop.' +
130
'%s%s See https://fb.me/react-warning-keys for more information.',
131
currentComponentErrorInfo,
132
childOwner,
packages/react/src/__tests__/ReactChildren-test.js
+3
-3
@@ -320,7 +320,7 @@ describe('ReactChildren', () => {
320
321
let instance;
322
expect(() => (instance = <div>{threeDivIterable}</div>)).toWarnDev(
323
- 'Warning: Each child in an array or iterator should have a unique "key" prop.',
323
+ 'Warning: Each child in a list should have a unique "key" prop.',
324
);
325
326
function assertCalls() {
@@ -905,7 +905,7 @@ describe('ReactChildren', () => {
905
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />),
906
).toWarnDev(
907
'Warning: ' +
908
- 'Each child in an array or iterator should have a unique "key" prop.' +
908
+ 'Each child in a list should have a unique "key" prop.' +
909
' See https://fb.me/react-warning-keys for more information.' +
910
'\n in ComponentReturningArray (at **)',
911
);
@@ -926,7 +926,7 @@ describe('ReactChildren', () => {
926
ReactTestUtils.renderIntoDocument([<div />, <div />]),
927
).toWarnDev(
928
'Warning: ' +
929
- 'Each child in an array or iterator should have a unique "key" prop.' +
929
+ 'Each child in a list should have a unique "key" prop.' +
930
' See https://fb.me/react-warning-keys for more information.',
931
{withoutStack: true}, // There's nothing on the stack
932
);
packages/react/src/__tests__/ReactElementClone-test.js
+1
-3
@@ -259,9 +259,7 @@ describe('ReactElementClone', () => {
259
it('warns for keys for arrays of elements in rest args', () => {
260
expect(() =>
261
React.cloneElement(<div />, null, [<div />, <div />]),
262
- ).toWarnDev(
263
- 'Each child in an array or iterator should have a unique "key" prop.',
264
- );
262
+ ).toWarnDev('Each child in a list should have a unique "key" prop.');
263
});
264
265
it('does not warns for arrays of elements with keys', () => {
packages/react/src/__tests__/ReactElementValidator-test.internal.js
+6
-8
@@ -42,9 +42,7 @@ describe('ReactElementValidator', () => {
42
43
expect(() => {
44
Component(null, [Component(), Component()]);
45
- }).toWarnDev(
46
- 'Each child in an array or iterator should have a unique "key" prop.',
47
- );
45
+ }).toWarnDev('Each child in a list should have a unique "key" prop.');
46
});
47
48
it('warns for keys for arrays of elements with owner info', () => {
@@ -67,7 +65,7 @@ describe('ReactElementValidator', () => {
65
expect(() => {
66
ReactTestUtils.renderIntoDocument(React.createElement(ComponentWrapper));
67
}).toWarnDev(
70
- 'Each child in an array or iterator should have a unique "key" prop.' +
68
+ 'Each child in a list should have a unique "key" prop.' +
69
'\n\nCheck the render method of `InnerClass`. ' +
70
'It was passed a child from ComponentWrapper. ',
71
);
@@ -84,7 +82,7 @@ describe('ReactElementValidator', () => {
82
expect(() => {
83
ReactTestUtils.renderIntoDocument(<Anonymous>{divs}</Anonymous>);
84
}).toWarnDev(
87
- 'Warning: Each child in an array or iterator should have a unique ' +
85
+ 'Warning: Each child in a list should have a unique ' +
86
'"key" prop. See https://fb.me/react-warning-keys for more information.\n' +
87
' in div (at **)',
88
);
@@ -96,7 +94,7 @@ describe('ReactElementValidator', () => {
94
expect(() => {
95
ReactTestUtils.renderIntoDocument(<div>{divs}</div>);
96
}).toWarnDev(
99
- 'Warning: Each child in an array or iterator should have a unique ' +
97
+ 'Warning: Each child in a list should have a unique ' +
98
'"key" prop.\n\nCheck the top-level render call using <div>. See ' +
99
'https://fb.me/react-warning-keys for more information.\n' +
100
' in div (at **)',
@@ -117,7 +115,7 @@ describe('ReactElementValidator', () => {
115
}
116
117
expect(() => ReactTestUtils.renderIntoDocument(<GrandParent />)).toWarnDev(
120
- 'Warning: Each child in an array or iterator should have a unique ' +
118
+ 'Warning: Each child in a list should have a unique ' +
119
'"key" prop.\n\nCheck the render method of `Component`. See ' +
120
'https://fb.me/react-warning-keys for more information.\n' +
121
' in div (at **)\n' +
@@ -161,7 +159,7 @@ describe('ReactElementValidator', () => {
159
};
160
161
expect(() => Component(null, iterable)).toWarnDev(
164
- 'Each child in an array or iterator should have a unique "key" prop.',
162
+ 'Each child in a list should have a unique "key" prop.',
163
);
164
});
165
packages/react/src/__tests__/ReactJSXElementValidator-test.js
+3
-7
@@ -48,9 +48,7 @@ describe('ReactJSXElementValidator', () => {
48
ReactTestUtils.renderIntoDocument(
49
<Component>{[<Component />, <Component />]}</Component>,
50
),
51
- ).toWarnDev(
52
- 'Each child in an array or iterator should have a unique "key" prop.',
53
- );
51
+ ).toWarnDev('Each child in a list should have a unique "key" prop.');
52
});
53
54
it('warns for keys for arrays of elements with owner info', () => {
@@ -69,7 +67,7 @@ describe('ReactJSXElementValidator', () => {
67
expect(() =>
68
ReactTestUtils.renderIntoDocument(<ComponentWrapper />),
69
).toWarnDev(
72
- 'Each child in an array or iterator should have a unique "key" prop.' +
70
+ 'Each child in a list should have a unique "key" prop.' +
71
'\n\nCheck the render method of `InnerComponent`. ' +
72
'It was passed a child from ComponentWrapper. ',
73
);
@@ -90,9 +88,7 @@ describe('ReactJSXElementValidator', () => {
88
89
expect(() =>
90
ReactTestUtils.renderIntoDocument(<Component>{iterable}</Component>),
93
- ).toWarnDev(
94
- 'Each child in an array or iterator should have a unique "key" prop.',
95
- );
91
+ ).toWarnDev('Each child in a list should have a unique "key" prop.');
92
});
93
94
it('does not warn for arrays of elements with keys', () => {