Don't modify keyPath until right before recursive renderNode call (#27366)

Currently, if a component suspends, the keyPath has already been
modified to include the identity of the component itself; the path is
set before the component body is called (akin to the begin phase in
Fiber). An accidental consequence is that when the promise resolves and
component is retried, the identity gets appended to the keyPath again,
leading to a duplicate node in the path.

To address this, we should only modify contexts after any code that may
suspend. For maximum safety, this should occur as late as possible:
right before the recursive renderNode call, before the children are
rendered.

I did not add a test yet because there's no feature that currently
observes it, but I do have tests in my other WIP PR for useFormState:
#27321

DiffTrain build for commit https://github.com/facebook/react/commit/d07921eeda62613bfcf52ecdb66322db26393567.
This commit is contained in:
acdlite
2023-09-13 01:32:20 +00:00
parent 6c133b6661
commit f73ef32f79
7 changed files with 9 additions and 9 deletions
@@ -23994,7 +23994,7 @@ function createFiberRoot(
return root;
}
var ReactVersion = "18.3.0-canary-7a3cb8f9c-20230912";
var ReactVersion = "18.3.0-canary-d07921eed-20230912";
// Might add PROFILE later.
@@ -8617,7 +8617,7 @@ var devToolsConfig$jscomp$inline_1027 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-7a3cb8f9c-20230912",
version: "18.3.0-canary-d07921eed-20230912",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1226 = {
@@ -8648,7 +8648,7 @@ var internals$jscomp$inline_1226 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-7a3cb8f9c-20230912"
reconcilerVersion: "18.3.0-canary-d07921eed-20230912"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1227 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -9043,7 +9043,7 @@ var devToolsConfig$jscomp$inline_1069 = {
throw Error("TestRenderer does not support findFiberByHostInstance()");
},
bundleType: 0,
version: "18.3.0-canary-7a3cb8f9c-20230912",
version: "18.3.0-canary-d07921eed-20230912",
rendererPackageName: "react-test-renderer"
};
var internals$jscomp$inline_1267 = {
@@ -9074,7 +9074,7 @@ var internals$jscomp$inline_1267 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-canary-7a3cb8f9c-20230912"
reconcilerVersion: "18.3.0-canary-d07921eed-20230912"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1268 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
@@ -27,7 +27,7 @@ if (
}
"use strict";
var ReactVersion = "18.3.0-canary-7a3cb8f9c-20230912";
var ReactVersion = "18.3.0-canary-d07921eed-20230912";
// ATTENTION
// When adding new symbols to this file,
@@ -616,4 +616,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-7a3cb8f9c-20230912";
exports.version = "18.3.0-canary-d07921eed-20230912";
@@ -619,7 +619,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "18.3.0-canary-7a3cb8f9c-20230912";
exports.version = "18.3.0-canary-d07921eed-20230912";
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
@@ -1 +1 @@
7a3cb8f9cf43591afc74722ece9e3216ccc98128
d07921eeda62613bfcf52ecdb66322db26393567