From 547e059f0bc88e76cd738b01b76e777ff1b222a7 Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Mon, 7 Jan 2019 08:30:23 -0800 Subject: [PATCH] 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. --- .../src/__tests__/ReactFunctionComponent-test.js | 2 +- .../src/__tests__/ReactMultiChildText-test.js | 4 ++-- packages/react-reconciler/src/ReactChildFiber.js | 4 ++-- .../src/__tests__/ReactFragment-test.js | 8 ++++---- packages/react/src/ReactElementValidator.js | 2 +- packages/react/src/__tests__/ReactChildren-test.js | 6 +++--- .../react/src/__tests__/ReactElementClone-test.js | 4 +--- .../ReactElementValidator-test.internal.js | 14 ++++++-------- .../src/__tests__/ReactJSXElementValidator-test.js | 10 +++------- 9 files changed, 23 insertions(+), 31 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js index 8fd8830787..7b7d5fa619 100644 --- a/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactFunctionComponent-test.js @@ -354,7 +354,7 @@ describe('ReactFunctionComponent', () => { } expect(() => ReactTestUtils.renderIntoDocument()).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.\n\n' + + 'Each child in a list should have a unique "key" prop.\n\n' + 'Check the render method of `Child`.', ); }); diff --git a/packages/react-dom/src/__tests__/ReactMultiChildText-test.js b/packages/react-dom/src/__tests__/ReactMultiChildText-test.js index 360860c00c..2785bd0304 100644 --- a/packages/react-dom/src/__tests__/ReactMultiChildText-test.js +++ b/packages/react-dom/src/__tests__/ReactMultiChildText-test.js @@ -162,8 +162,8 @@ describe('ReactMultiChildText', () => { ['', 'foo',
{true}{
}{1.2}{''}
, 'foo'], ['', 'foo',
, 'foo'], ]); }).toWarnDev([ - 'Warning: Each child in an array or iterator should have a unique "key" prop.', - 'Warning: Each child in an array or iterator should have a unique "key" prop.', + 'Warning: Each child in a list should have a unique "key" prop.', + 'Warning: Each child in a list should have a unique "key" prop.', ]); }); diff --git a/packages/react-reconciler/src/ReactChildFiber.js b/packages/react-reconciler/src/ReactChildFiber.js index bed780c2b1..fd1aa488c6 100644 --- a/packages/react-reconciler/src/ReactChildFiber.js +++ b/packages/react-reconciler/src/ReactChildFiber.js @@ -80,7 +80,7 @@ if (__DEV__) { child._store.validated = true; const currentComponentErrorInfo = - 'Each child in an array or iterator should have a unique ' + + 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.' + getCurrentFiberStackInDev(); @@ -91,7 +91,7 @@ if (__DEV__) { warning( false, - 'Each child in an array or iterator should have a unique ' + + 'Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for ' + 'more information.', ); diff --git a/packages/react-reconciler/src/__tests__/ReactFragment-test.js b/packages/react-reconciler/src/__tests__/ReactFragment-test.js index a742ac0884..d6b8b41fc0 100644 --- a/packages/react-reconciler/src/__tests__/ReactFragment-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFragment-test.js @@ -709,7 +709,7 @@ describe('ReactFragment', () => { ReactNoop.render(); expect(ReactNoop.flush).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', + 'Each child in a list should have a unique "key" prop.', ); expect(ops).toEqual([]); @@ -753,12 +753,12 @@ describe('ReactFragment', () => { ReactNoop.render(); expect(ReactNoop.flush).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', + 'Each child in a list should have a unique "key" prop.', ); ReactNoop.render(); expect(ReactNoop.flush).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', + 'Each child in a list should have a unique "key" prop.', ); expect(ops).toEqual(['Update Stateful']); @@ -766,7 +766,7 @@ describe('ReactFragment', () => { ReactNoop.render(); expect(ReactNoop.flush).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', + 'Each child in a list should have a unique "key" prop.', ); expect(ops).toEqual(['Update Stateful', 'Update Stateful']); diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index f25677580e..fa83aea4ef 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -126,7 +126,7 @@ function validateExplicitKey(element, parentType) { if (__DEV__) { warning( false, - 'Each child in an array or iterator should have a unique "key" prop.' + + 'Each child in a list should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.', currentComponentErrorInfo, childOwner, diff --git a/packages/react/src/__tests__/ReactChildren-test.js b/packages/react/src/__tests__/ReactChildren-test.js index 5dc7a9155a..68165197ef 100644 --- a/packages/react/src/__tests__/ReactChildren-test.js +++ b/packages/react/src/__tests__/ReactChildren-test.js @@ -320,7 +320,7 @@ describe('ReactChildren', () => { let instance; expect(() => (instance =
{threeDivIterable}
)).toWarnDev( - 'Warning: Each child in an array or iterator should have a unique "key" prop.', + 'Warning: Each child in a list should have a unique "key" prop.', ); function assertCalls() { @@ -905,7 +905,7 @@ describe('ReactChildren', () => { ReactTestUtils.renderIntoDocument(), ).toWarnDev( 'Warning: ' + - 'Each child in an array or iterator should have a unique "key" prop.' + + 'Each child in a list should have a unique "key" prop.' + ' See https://fb.me/react-warning-keys for more information.' + '\n in ComponentReturningArray (at **)', ); @@ -926,7 +926,7 @@ describe('ReactChildren', () => { ReactTestUtils.renderIntoDocument([
,
]), ).toWarnDev( 'Warning: ' + - 'Each child in an array or iterator should have a unique "key" prop.' + + 'Each child in a list should have a unique "key" prop.' + ' See https://fb.me/react-warning-keys for more information.', {withoutStack: true}, // There's nothing on the stack ); diff --git a/packages/react/src/__tests__/ReactElementClone-test.js b/packages/react/src/__tests__/ReactElementClone-test.js index 722bff24ee..2220a7b112 100644 --- a/packages/react/src/__tests__/ReactElementClone-test.js +++ b/packages/react/src/__tests__/ReactElementClone-test.js @@ -259,9 +259,7 @@ describe('ReactElementClone', () => { it('warns for keys for arrays of elements in rest args', () => { expect(() => React.cloneElement(
, null, [
,
]), - ).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', - ); + ).toWarnDev('Each child in a list should have a unique "key" prop.'); }); it('does not warns for arrays of elements with keys', () => { diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 5a17a079bc..d4c7f9bf2a 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -42,9 +42,7 @@ describe('ReactElementValidator', () => { expect(() => { Component(null, [Component(), Component()]); - }).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', - ); + }).toWarnDev('Each child in a list should have a unique "key" prop.'); }); it('warns for keys for arrays of elements with owner info', () => { @@ -67,7 +65,7 @@ describe('ReactElementValidator', () => { expect(() => { ReactTestUtils.renderIntoDocument(React.createElement(ComponentWrapper)); }).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.' + + 'Each child in a list should have a unique "key" prop.' + '\n\nCheck the render method of `InnerClass`. ' + 'It was passed a child from ComponentWrapper. ', ); @@ -84,7 +82,7 @@ describe('ReactElementValidator', () => { expect(() => { ReactTestUtils.renderIntoDocument({divs}); }).toWarnDev( - 'Warning: Each child in an array or iterator should have a unique ' + + 'Warning: Each child in a list should have a unique ' + '"key" prop. See https://fb.me/react-warning-keys for more information.\n' + ' in div (at **)', ); @@ -96,7 +94,7 @@ describe('ReactElementValidator', () => { expect(() => { ReactTestUtils.renderIntoDocument(
{divs}
); }).toWarnDev( - 'Warning: Each child in an array or iterator should have a unique ' + + 'Warning: Each child in a list should have a unique ' + '"key" prop.\n\nCheck the top-level render call using
. See ' + 'https://fb.me/react-warning-keys for more information.\n' + ' in div (at **)', @@ -117,7 +115,7 @@ describe('ReactElementValidator', () => { } expect(() => ReactTestUtils.renderIntoDocument()).toWarnDev( - 'Warning: Each child in an array or iterator should have a unique ' + + 'Warning: Each child in a list should have a unique ' + '"key" prop.\n\nCheck the render method of `Component`. See ' + 'https://fb.me/react-warning-keys for more information.\n' + ' in div (at **)\n' + @@ -161,7 +159,7 @@ describe('ReactElementValidator', () => { }; expect(() => Component(null, iterable)).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', + 'Each child in a list should have a unique "key" prop.', ); }); diff --git a/packages/react/src/__tests__/ReactJSXElementValidator-test.js b/packages/react/src/__tests__/ReactJSXElementValidator-test.js index 24fe79fdb1..0321e5cd22 100644 --- a/packages/react/src/__tests__/ReactJSXElementValidator-test.js +++ b/packages/react/src/__tests__/ReactJSXElementValidator-test.js @@ -48,9 +48,7 @@ describe('ReactJSXElementValidator', () => { ReactTestUtils.renderIntoDocument( {[, ]}, ), - ).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', - ); + ).toWarnDev('Each child in a list should have a unique "key" prop.'); }); it('warns for keys for arrays of elements with owner info', () => { @@ -69,7 +67,7 @@ describe('ReactJSXElementValidator', () => { expect(() => ReactTestUtils.renderIntoDocument(), ).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.' + + 'Each child in a list should have a unique "key" prop.' + '\n\nCheck the render method of `InnerComponent`. ' + 'It was passed a child from ComponentWrapper. ', ); @@ -90,9 +88,7 @@ describe('ReactJSXElementValidator', () => { expect(() => ReactTestUtils.renderIntoDocument({iterable}), - ).toWarnDev( - 'Each child in an array or iterator should have a unique "key" prop.', - ); + ).toWarnDev('Each child in a list should have a unique "key" prop.'); }); it('does not warn for arrays of elements with keys', () => {