Skip to content

Commit 547e059

Browse files
authored
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.
1 parent 3494ee5 commit 547e059

9 files changed

+23
-31
lines changed

Diff for: packages/react-dom/src/__tests__/ReactFunctionComponent-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe('ReactFunctionComponent', () => {
354354
}
355355

356356
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' +
358358
'Check the render method of `Child`.',
359359
);
360360
});

Diff for: packages/react-dom/src/__tests__/ReactMultiChildText-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ describe('ReactMultiChildText', () => {
162162
['', 'foo', <div>{true}{<div />}{1.2}{''}</div>, 'foo'], ['', 'foo', <div />, 'foo'],
163163
]);
164164
}).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.',
167167
]);
168168
});
169169

Diff for: packages/react-reconciler/src/ReactChildFiber.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if (__DEV__) {
8080
child._store.validated = true;
8181

8282
const currentComponentErrorInfo =
83-
'Each child in an array or iterator should have a unique ' +
83+
'Each child in a list should have a unique ' +
8484
'"key" prop. See https://fb.me/react-warning-keys for ' +
8585
'more information.' +
8686
getCurrentFiberStackInDev();
@@ -91,7 +91,7 @@ if (__DEV__) {
9191

9292
warning(
9393
false,
94-
'Each child in an array or iterator should have a unique ' +
94+
'Each child in a list should have a unique ' +
9595
'"key" prop. See https://fb.me/react-warning-keys for ' +
9696
'more information.',
9797
);

Diff for: packages/react-reconciler/src/__tests__/ReactFragment-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ describe('ReactFragment', () => {
709709

710710
ReactNoop.render(<Foo condition={false} />);
711711
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.',
713713
);
714714

715715
expect(ops).toEqual([]);
@@ -753,20 +753,20 @@ describe('ReactFragment', () => {
753753

754754
ReactNoop.render(<Foo condition={true} />);
755755
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.',
757757
);
758758

759759
ReactNoop.render(<Foo condition={false} />);
760760
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.',
762762
);
763763

764764
expect(ops).toEqual(['Update Stateful']);
765765
expect(ReactNoop.getChildren()).toEqual([span(), div()]);
766766

767767
ReactNoop.render(<Foo condition={true} />);
768768
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.',
770770
);
771771

772772
expect(ops).toEqual(['Update Stateful', 'Update Stateful']);

Diff for: packages/react/src/ReactElementValidator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function validateExplicitKey(element, parentType) {
126126
if (__DEV__) {
127127
warning(
128128
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.' +
130130
'%s%s See https://fb.me/react-warning-keys for more information.',
131131
currentComponentErrorInfo,
132132
childOwner,

Diff for: packages/react/src/__tests__/ReactChildren-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe('ReactChildren', () => {
320320

321321
let instance;
322322
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.',
324324
);
325325

326326
function assertCalls() {
@@ -905,7 +905,7 @@ describe('ReactChildren', () => {
905905
ReactTestUtils.renderIntoDocument(<ComponentReturningArray />),
906906
).toWarnDev(
907907
'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.' +
909909
' See https://fb.me/react-warning-keys for more information.' +
910910
'\n in ComponentReturningArray (at **)',
911911
);
@@ -926,7 +926,7 @@ describe('ReactChildren', () => {
926926
ReactTestUtils.renderIntoDocument([<div />, <div />]),
927927
).toWarnDev(
928928
'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.' +
930930
' See https://fb.me/react-warning-keys for more information.',
931931
{withoutStack: true}, // There's nothing on the stack
932932
);

Diff for: packages/react/src/__tests__/ReactElementClone-test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ describe('ReactElementClone', () => {
259259
it('warns for keys for arrays of elements in rest args', () => {
260260
expect(() =>
261261
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.');
265263
});
266264

267265
it('does not warns for arrays of elements with keys', () => {

Diff for: packages/react/src/__tests__/ReactElementValidator-test.internal.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ describe('ReactElementValidator', () => {
4242

4343
expect(() => {
4444
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.');
4846
});
4947

5048
it('warns for keys for arrays of elements with owner info', () => {
@@ -67,7 +65,7 @@ describe('ReactElementValidator', () => {
6765
expect(() => {
6866
ReactTestUtils.renderIntoDocument(React.createElement(ComponentWrapper));
6967
}).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.' +
7169
'\n\nCheck the render method of `InnerClass`. ' +
7270
'It was passed a child from ComponentWrapper. ',
7371
);
@@ -84,7 +82,7 @@ describe('ReactElementValidator', () => {
8482
expect(() => {
8583
ReactTestUtils.renderIntoDocument(<Anonymous>{divs}</Anonymous>);
8684
}).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 ' +
8886
'"key" prop. See https://fb.me/react-warning-keys for more information.\n' +
8987
' in div (at **)',
9088
);
@@ -96,7 +94,7 @@ describe('ReactElementValidator', () => {
9694
expect(() => {
9795
ReactTestUtils.renderIntoDocument(<div>{divs}</div>);
9896
}).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 ' +
10098
'"key" prop.\n\nCheck the top-level render call using <div>. See ' +
10199
'https://fb.me/react-warning-keys for more information.\n' +
102100
' in div (at **)',
@@ -117,7 +115,7 @@ describe('ReactElementValidator', () => {
117115
}
118116

119117
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 ' +
121119
'"key" prop.\n\nCheck the render method of `Component`. See ' +
122120
'https://fb.me/react-warning-keys for more information.\n' +
123121
' in div (at **)\n' +
@@ -161,7 +159,7 @@ describe('ReactElementValidator', () => {
161159
};
162160

163161
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.',
165163
);
166164
});
167165

Diff for: packages/react/src/__tests__/ReactJSXElementValidator-test.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ describe('ReactJSXElementValidator', () => {
4848
ReactTestUtils.renderIntoDocument(
4949
<Component>{[<Component />, <Component />]}</Component>,
5050
),
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.');
5452
});
5553

5654
it('warns for keys for arrays of elements with owner info', () => {
@@ -69,7 +67,7 @@ describe('ReactJSXElementValidator', () => {
6967
expect(() =>
7068
ReactTestUtils.renderIntoDocument(<ComponentWrapper />),
7169
).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.' +
7371
'\n\nCheck the render method of `InnerComponent`. ' +
7472
'It was passed a child from ComponentWrapper. ',
7573
);
@@ -90,9 +88,7 @@ describe('ReactJSXElementValidator', () => {
9088

9189
expect(() =>
9290
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.');
9692
});
9793

9894
it('does not warn for arrays of elements with keys', () => {

0 commit comments

Comments
 (0)