Skip to content

Commit 6de1973

Browse files
committed
Fix Missing key Validation in React.Children (#29675)
## Summary In #29088, the validation logic for `React.Children` inspected whether `mappedChild` — the return value of the map callback — has a valid `key`. However, this deviates from existing behavior which only warns if the original `child` is missing a required `key`. This fixes false positive `key` validation warnings when using `React.Children`, by validating the original `child` instead of `mappedChild`. This is a more general fix that expands upon my previous fix in #29662. ## How did you test this change? ``` $ yarn test ReactChildren-test.js ``` DiffTrain build for commit 8fd963a.
1 parent 916c781 commit 6de1973

File tree

13 files changed

+45
-40
lines changed

13 files changed

+45
-40
lines changed

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-dev.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<2a25705fbbe871438d92d9d2f32bfccc>>
10+
* @generated SignedSource<<51857d1396b3dbf84785badc368366e6>>
1111
*/
1212

1313
'use strict';
@@ -23471,7 +23471,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
2347123471
return root;
2347223472
}
2347323473

23474-
var ReactVersion = '19.0.0-rc-aa3d6c0840-20240530';
23474+
var ReactVersion = '19.0.0-rc-8fd963a1e5-20240530';
2347523475

2347623476
/*
2347723477
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-prod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<3d4979729ff28e957f06f4727c93a3a4>>
10+
* @generated SignedSource<<62a7ec5b565b86a1ca4e89a8b6dfa33a>>
1111
*/
1212

1313
"use strict";
@@ -9298,7 +9298,7 @@ var devToolsConfig$jscomp$inline_1047 = {
92989298
throw Error("TestRenderer does not support findFiberByHostInstance()");
92999299
},
93009300
bundleType: 0,
9301-
version: "19.0.0-rc-aa3d6c0840-20240530",
9301+
version: "19.0.0-rc-8fd963a1e5-20240530",
93029302
rendererPackageName: "react-test-renderer"
93039303
};
93049304
var internals$jscomp$inline_1234 = {
@@ -9329,7 +9329,7 @@ var internals$jscomp$inline_1234 = {
93299329
scheduleRoot: null,
93309330
setRefreshHandler: null,
93319331
getCurrentFiber: null,
9332-
reconcilerVersion: "19.0.0-rc-aa3d6c0840-20240530"
9332+
reconcilerVersion: "19.0.0-rc-8fd963a1e5-20240530"
93339333
};
93349334
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
93359335
var hook$jscomp$inline_1235 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react-test-renderer/cjs/ReactTestRenderer-profiling.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<14d991ff27c63a57f423b8548b3f34ad>>
10+
* @generated SignedSource<<4ac434762822d6280d83c5cda5c1341b>>
1111
*/
1212

1313
"use strict";
@@ -9920,7 +9920,7 @@ var devToolsConfig$jscomp$inline_1130 = {
99209920
throw Error("TestRenderer does not support findFiberByHostInstance()");
99219921
},
99229922
bundleType: 0,
9923-
version: "19.0.0-rc-aa3d6c0840-20240530",
9923+
version: "19.0.0-rc-8fd963a1e5-20240530",
99249924
rendererPackageName: "react-test-renderer"
99259925
};
99269926
(function (internals) {
@@ -9964,7 +9964,7 @@ var devToolsConfig$jscomp$inline_1130 = {
99649964
scheduleRoot: null,
99659965
setRefreshHandler: null,
99669966
getCurrentFiber: null,
9967-
reconcilerVersion: "19.0.0-rc-aa3d6c0840-20240530"
9967+
reconcilerVersion: "19.0.0-rc-8fd963a1e5-20240530"
99689968
});
99699969
exports._Scheduler = Scheduler;
99709970
exports.act = act;

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-dev.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<f2d4c82ad9e691aab626fdc02f31be82>>
10+
* @generated SignedSource<<d88d69aa4000a33e09ec957377ca26f8>>
1111
*/
1212

1313
'use strict';
@@ -24,7 +24,7 @@ if (
2424
}
2525
var dynamicFlagsUntyped = require('ReactNativeInternalFeatureFlags');
2626

27-
var ReactVersion = '19.0.0-rc-aa3d6c0840-20240530';
27+
var ReactVersion = '19.0.0-rc-8fd963a1e5-20240530';
2828

2929
// Re-export dynamic flags from the internal module.
3030
var dynamicFlags = dynamicFlagsUntyped; // We destructure each value before re-exporting to avoid a dynamic look-up on
@@ -2011,11 +2011,16 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
20112011
) + '/' : '') + childKey);
20122012

20132013
{
2014-
if (nameSoFar !== '' && mappedChild.key == null) {
2015-
// We need to validate that this child should have had a key before assigning it one.
2016-
if (!newChild._store.validated) {
2017-
// We mark this child as having failed validation but we let the actual renderer
2018-
// print the warning later.
2014+
// If `child` was an element without a `key`, we need to validate if
2015+
// it should have had a `key`, before assigning one to `mappedChild`.
2016+
// $FlowFixMe[incompatible-type] Flow incorrectly thinks React.Portal doesn't have a key
2017+
if (nameSoFar !== '' && _child != null && isValidElement(_child) && _child.key == null) {
2018+
// We check truthiness of `child._store.validated` instead of being
2019+
// inequal to `1` to provide a bit of backward compatibility for any
2020+
// libraries (like `fbt`) which may be hacking this property.
2021+
if (_child._store && !_child._store.validated) {
2022+
// Mark this child as having failed validation, but let the actual
2023+
// renderer print the warning later.
20192024
newChild._store.validated = 2;
20202025
}
20212026
}

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-prod.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e286590d896e861b94dedb356ce7ecea>>
10+
* @generated SignedSource<<4cc9db1802bfed728048b5d62af26b8b>>
1111
*/
1212

1313
"use strict";
@@ -604,4 +604,4 @@ exports.useSyncExternalStore = function (
604604
exports.useTransition = function () {
605605
return ReactSharedInternals.H.useTransition();
606606
};
607-
exports.version = "19.0.0-rc-aa3d6c0840-20240530";
607+
exports.version = "19.0.0-rc-8fd963a1e5-20240530";

compiled-rn/facebook-fbsource/xplat/js/RKJSModules/vendor/react/react/cjs/React-profiling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<86e1e6d22f22b9f5dcddbb5c1ecb70ca>>
10+
* @generated SignedSource<<c411b87ad31eb8487965b83bc03b44eb>>
1111
*/
1212

1313
"use strict";
@@ -608,7 +608,7 @@ exports.useSyncExternalStore = function (
608608
exports.useTransition = function () {
609609
return ReactSharedInternals.H.useTransition();
610610
};
611-
exports.version = "19.0.0-rc-aa3d6c0840-20240530";
611+
exports.version = "19.0.0-rc-8fd963a1e5-20240530";
612612
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
613613
"function" ===
614614
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
aa3d6c0840357eb469df9bd1c20b201197ce3bdc
1+
8fd963a1e5ec89459cac27fb1d9ad193a0604110

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<7e84a017485205dca1fd369d6e72a750>>
10+
* @generated SignedSource<<561a3a04b6eef3ab839c5c6c89289a8f>>
1111
*/
1212

1313
'use strict';
@@ -26206,7 +26206,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
2620626206
return root;
2620726207
}
2620826208

26209-
var ReactVersion = '19.0.0-rc-aa3d6c0840-20240530';
26209+
var ReactVersion = '19.0.0-rc-8fd963a1e5-20240530';
2621026210

2621126211
/*
2621226212
* The `'' + value` pattern (used in perf-sensitive code) throws for Symbol

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-prod.fb.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<29814ea154ff0145564ba37bc7c641e3>>
10+
* @generated SignedSource<<43e2d3a64b19f02f63428367b171ef83>>
1111
*/
1212

1313
"use strict";
@@ -10551,7 +10551,7 @@ var roots = new Map(),
1055110551
devToolsConfig$jscomp$inline_1124 = {
1055210552
findFiberByHostInstance: getInstanceFromNode,
1055310553
bundleType: 0,
10554-
version: "19.0.0-rc-aa3d6c0840-20240530",
10554+
version: "19.0.0-rc-8fd963a1e5-20240530",
1055510555
rendererPackageName: "react-native-renderer",
1055610556
rendererConfig: {
1055710557
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -10594,7 +10594,7 @@ var internals$jscomp$inline_1350 = {
1059410594
scheduleRoot: null,
1059510595
setRefreshHandler: null,
1059610596
getCurrentFiber: null,
10597-
reconcilerVersion: "19.0.0-rc-aa3d6c0840-20240530"
10597+
reconcilerVersion: "19.0.0-rc-8fd963a1e5-20240530"
1059810598
};
1059910599
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
1060010600
var hook$jscomp$inline_1351 = __REACT_DEVTOOLS_GLOBAL_HOOK__;

compiled-rn/facebook-fbsource/xplat/js/react-native-github/Libraries/Renderer/implementations/ReactFabric-profiling.fb.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @noflow
88
* @nolint
99
* @preventMunge
10-
* @generated SignedSource<<e19877e45f15454540281567e670bc5b>>
10+
* @generated SignedSource<<01c2ef8f2c76da87ab46ae77a3777990>>
1111
*/
1212

1313
"use strict";
@@ -11257,7 +11257,7 @@ var roots = new Map(),
1125711257
devToolsConfig$jscomp$inline_1205 = {
1125811258
findFiberByHostInstance: getInstanceFromNode,
1125911259
bundleType: 0,
11260-
version: "19.0.0-rc-aa3d6c0840-20240530",
11260+
version: "19.0.0-rc-8fd963a1e5-20240530",
1126111261
rendererPackageName: "react-native-renderer",
1126211262
rendererConfig: {
1126311263
getInspectorDataForInstance: getInspectorDataForInstance,
@@ -11313,7 +11313,7 @@ var roots = new Map(),
1131311313
scheduleRoot: null,
1131411314
setRefreshHandler: null,
1131511315
getCurrentFiber: null,
11316-
reconcilerVersion: "19.0.0-rc-aa3d6c0840-20240530"
11316+
reconcilerVersion: "19.0.0-rc-8fd963a1e5-20240530"
1131711317
});
1131811318
exports.createPortal = function (children, containerTag) {
1131911319
return createPortal$1(

0 commit comments

Comments
 (0)