GeezerVison is showing github.com — Feature Flag for React.jsx` "spreading a key to jsx" warning (#18074) · react/react@b789060
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react/src/ReactElementValidator.js +11-7Lines changed: 11 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,7 @@ import { | 21 | 21 | REACT_FRAGMENT_TYPE, | 22 | 22 | REACT_ELEMENT_TYPE, | 23 | 23 | } from 'shared/ReactSymbols'; | | 24 | +import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags'; | 24 | 25 | import checkPropTypes from 'prop-types/checkPropTypes'; | 25 | 26 |
| 26 | 27 | import ReactCurrentOwner from './ReactCurrentOwner'; | @@ -365,13 +366,16 @@ export function jsxWithValidation( | 365 | 366 | } | 366 | 367 | } | 367 | 368 |
| 368 | | - if (hasOwnProperty.call(props, 'key')) { | 369 | | - if (__DEV__) { | 370 | | - console.error( | 371 | | - 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' + | 372 | | - 'Explicitly pass a key after spreading props in your JSX call. ' + | 373 | | - 'E.g. <ComponentName {...props} key={key} />', | 374 | | - ); | | 369 | + if (__DEV__) { | | 370 | + if (warnAboutSpreadingKeyToJSX) { | | 371 | + if (hasOwnProperty.call(props, 'key')) { | | 372 | + console.error( | | 373 | + 'React.jsx: Spreading a key to JSX is a deprecated pattern. ' + | | 374 | + 'Explicitly pass a key after spreading props in your JSX call. ' + | | 375 | + 'E.g. <%s {...props} key={key} />', | | 376 | + getComponentName(type) || 'ComponentName', | | 377 | + ); | | 378 | + } | 375 | 379 | } | 376 | 380 | } | 377 | 381 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/__tests__/ReactElementJSX-test.internal.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,6 +32,7 @@ describe('ReactElement.jsx', () => { | 32 | 32 |
| 33 | 33 | ReactFeatureFlags = require('shared/ReactFeatureFlags'); | 34 | 34 | ReactFeatureFlags.enableJSXTransformAPI = true; | | 35 | + ReactFeatureFlags.warnAboutSpreadingKeyToJSX = true; | 35 | 36 |
| 36 | 37 | React = require('react'); | 37 | 38 | ReactDOM = require('react-dom'); | @@ -371,7 +372,7 @@ describe('ReactElement.jsx', () => { | 371 | 372 | expect(() => ReactDOM.render(React.jsx(Parent, {}), container)).toErrorDev( | 372 | 373 | 'Warning: React.jsx: Spreading a key to JSX is a deprecated pattern. ' + | 373 | 374 | 'Explicitly pass a key after spreading props in your JSX call. ' + | 374 | | - 'E.g. <ComponentName {...props} key={key} />', | | 375 | + 'E.g. <Child {...props} key={key} />', | 375 | 376 | ); | 376 | 377 | }); | 377 | 378 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/ReactFeatureFlags.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -48,6 +48,8 @@ export const disableJavaScriptURLs = false; | 48 | 48 | // Control this behavior with a flag to support 16.6 minor releases in the meanwhile. | 49 | 49 | export const exposeConcurrentModeAPIs = __EXPERIMENTAL__; | 50 | 50 |
| | 51 | +// Warns when a combination of updates on a dom can cause a style declaration | | 52 | +// that clashes with a previous one https://github.com/facebook/react/pull/14181 | 51 | 53 | export const warnAboutShorthandPropertyCollision = true; | 52 | 54 |
| 53 | 55 | // Experimental React Flare event system and event components support. | @@ -106,8 +108,14 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; | 106 | 108 | // WARNING This flag only has an affect if used with runAllPassiveEffectDestroysBeforeCreates. | 107 | 109 | export const deferPassiveEffectCleanupDuringUnmount = false; | 108 | 110 |
| | 111 | +// Use this flag to generate "testing" builds, that include APIs like act() | | 112 | +// and extra warnings/errors | 109 | 113 | export const isTestEnvironment = false; | 110 | 114 |
| | 115 | +// Enables a warning when trying to spread a 'key' to an element; | | 116 | +// a deprecated pattern we want to get rid of in the future | | 117 | +export const warnAboutSpreadingKeyToJSX = false; | | 118 | + | 111 | 119 | // -------------------------- | 112 | 120 | // Future APIs to be deprecated | 113 | 121 | // -------------------------- | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-fb.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -56,6 +56,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 56 | 56 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 57 | 57 | export const isTestEnvironment = false; | 58 | 58 | export const enableModernEventSystem = false; | | 59 | +export const warnAboutSpreadingKeyToJSX = false; | 59 | 60 |
| 60 | 61 | // Only used in www builds. | 61 | 62 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-oss.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = false; | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.persistent.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = false; | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.test-renderer.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = true; // this should probably *never* change | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = true; // this should probably *never* change | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.testing.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = true; | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.testing.www.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,7 @@ export const deferPassiveEffectCleanupDuringUnmount = false; | 51 | 51 | export const runAllPassiveEffectDestroysBeforeCreates = false; | 52 | 52 | export const isTestEnvironment = true; | 53 | 53 | export const enableModernEventSystem = false; | | 54 | +export const warnAboutSpreadingKeyToJSX = false; | 54 | 55 |
| 55 | 56 | // Only used in www builds. | 56 | 57 | export function addUserTimingListener() { | |
|