From 89c627488fde570f3d02fdc2f72d9af8b6703192 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Thu, 6 Feb 2020 12:33:09 +0000 Subject: [PATCH] Add feature flag for removing children Map support Update flags Update flags --- packages/react/src/ReactChildren.js | 21 +++++++++++++------ packages/shared/ReactFeatureFlags.js | 7 +++++-- .../forks/ReactFeatureFlags.native-fb.js | 1 + .../forks/ReactFeatureFlags.native-oss.js | 1 + .../forks/ReactFeatureFlags.persistent.js | 1 + .../forks/ReactFeatureFlags.test-renderer.js | 1 + .../ReactFeatureFlags.test-renderer.www.js | 1 + .../shared/forks/ReactFeatureFlags.testing.js | 1 + .../shared/forks/ReactFeatureFlags.www.js | 2 ++ scripts/error-codes/codes.json | 3 ++- 10 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/react/src/ReactChildren.js b/packages/react/src/ReactChildren.js index 5941e1a75150c..9329d89c57c16 100644 --- a/packages/react/src/ReactChildren.js +++ b/packages/react/src/ReactChildren.js @@ -11,6 +11,7 @@ import { REACT_ELEMENT_TYPE, REACT_PORTAL_TYPE, } from 'shared/ReactSymbols'; +import {disableMapsAsChildren} from 'shared/ReactFeatureFlags'; import {isValidElement, cloneAndReplaceKey} from './ReactElement'; import ReactDebugCurrentFrame from './ReactDebugCurrentFrame'; @@ -158,14 +159,22 @@ function traverseAllChildrenImpl( } else { const iteratorFn = getIteratorFn(children); if (typeof iteratorFn === 'function') { - if (__DEV__) { + if (iteratorFn === children.entries) { + if (disableMapsAsChildren) { + invariant( + false, + 'Maps are not valid as a React child (found: %s). Consider converting ' + + 'children to an array of keyed ReactElements instead.', + children, + ); + } // Warn about using Maps as children - if (iteratorFn === children.entries) { + if (__DEV__) { if (!didWarnAboutMaps) { - console.error( - 'Using Maps as children is unsupported and will likely yield ' + - 'unexpected results. Convert it to a sequence/iterable of keyed ' + - 'ReactElements instead.', + console.warn( + 'Using Maps as children is deprecated and will be removed in ' + + 'a future major release. Consider converting children to ' + + 'an array of keyed ReactElements instead.', ); } didWarnAboutMaps = true; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index 7a3b8880ac8b9..469e5c5e810a5 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -97,6 +97,8 @@ export const enableNativeTargetAsInstance = false; // This flag provides a killswitch if that proves to break existing code somehow. export const deferPassiveEffectCleanupDuringUnmount = false; +export const isTestEnvironment = false; + // -------------------------- // Future APIs to be deprecated // -------------------------- @@ -115,6 +117,9 @@ export const disableCreateFactory = false; // Disables children for