Skip to content

Commit b4569e1

Browse files
committed
[Flight] Clear chunk reason after successful module initialization (react#36024)
When `requireModule` triggers a reentrant `readChunk` on the same module chunk, the reentrant call can fail and set `chunk.reason` to an error. After the outer `requireModule` succeeds, the chunk transitions to initialized but retains the stale error as `reason`. When the Flight response stream later closes, it iterates all chunks and expects `reason` on initialized chunks to be a `FlightStreamController`. Since the stale `reason` is an `Error` object instead, calling `chunk.reason.error()` crashes with `TypeError: chunk.reason.error is not a function`. The reentrancy can occur when module evaluation synchronously triggers `readChunk` on the same chunk — for example, when code called during evaluation tries to resolve the client reference for the module that is currently being initialized. In Fizz SSR, `captureOwnerStack()` can trigger this because it constructs component stacks that resolve lazy client references via `readChunk`. The reentrant `requireModule` call returns the module's namespace object, but since the module is still being evaluated, accessing the export binding throws a TDZ (Temporal Dead Zone) `ReferenceError`. This sets the chunk to the errored state, and the `ReferenceError` becomes the stale `chunk.reason` after the outer call succeeds. This scenario is triggered in Next.js when a client module calls an instrumented API like `Math.random()` in module scope, which synchronously invokes `captureOwnerStack()`. DiffTrain build for [5e9eedb](react@5e9eedb)
1 parent c50611d commit b4569e1

34 files changed

Lines changed: 178 additions & 102 deletions

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4610359651fa10247159e2050f8ec222cb7faa91
1+
5e9eedb57843dc161defdf93ed457ab7d982e324
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4610359651fa10247159e2050f8ec222cb7faa91
1+
5e9eedb57843dc161defdf93ed457ab7d982e324

compiled/facebook-www/React-dev.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ __DEV__ &&
14821482
exports.useTransition = function () {
14831483
return resolveDispatcher().useTransition();
14841484
};
1485-
exports.version = "19.3.0-www-classic-46103596-20260305";
1485+
exports.version = "19.3.0-www-classic-5e9eedb5-20260312";
14861486
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14871487
"function" ===
14881488
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-dev.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ __DEV__ &&
14821482
exports.useTransition = function () {
14831483
return resolveDispatcher().useTransition();
14841484
};
1485-
exports.version = "19.3.0-www-modern-46103596-20260305";
1485+
exports.version = "19.3.0-www-modern-5e9eedb5-20260312";
14861486
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
14871487
"function" ===
14881488
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-prod.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-classic-46103596-20260305";
613+
exports.version = "19.3.0-www-classic-5e9eedb5-20260312";

compiled/facebook-www/React-prod.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,4 @@ exports.useSyncExternalStore = function (
610610
exports.useTransition = function () {
611611
return ReactSharedInternals.H.useTransition();
612612
};
613-
exports.version = "19.3.0-www-modern-46103596-20260305";
613+
exports.version = "19.3.0-www-modern-5e9eedb5-20260312";

compiled/facebook-www/React-profiling.classic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.3.0-www-classic-46103596-20260305";
617+
exports.version = "19.3.0-www-classic-5e9eedb5-20260312";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/React-profiling.modern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ exports.useSyncExternalStore = function (
614614
exports.useTransition = function () {
615615
return ReactSharedInternals.H.useTransition();
616616
};
617-
exports.version = "19.3.0-www-modern-46103596-20260305";
617+
exports.version = "19.3.0-www-modern-5e9eedb5-20260312";
618618
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
619619
"function" ===
620620
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.classic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20400,10 +20400,10 @@ __DEV__ &&
2040020400
(function () {
2040120401
var internals = {
2040220402
bundleType: 1,
20403-
version: "19.3.0-www-classic-46103596-20260305",
20403+
version: "19.3.0-www-classic-5e9eedb5-20260312",
2040420404
rendererPackageName: "react-art",
2040520405
currentDispatcherRef: ReactSharedInternals,
20406-
reconcilerVersion: "19.3.0-www-classic-46103596-20260305"
20406+
reconcilerVersion: "19.3.0-www-classic-5e9eedb5-20260312"
2040720407
};
2040820408
internals.overrideHookState = overrideHookState;
2040920409
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20438,7 +20438,7 @@ __DEV__ &&
2043820438
exports.Shape = Shape;
2043920439
exports.Surface = Surface;
2044020440
exports.Text = Text;
20441-
exports.version = "19.3.0-www-classic-46103596-20260305";
20441+
exports.version = "19.3.0-www-classic-5e9eedb5-20260312";
2044220442
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2044320443
"function" ===
2044420444
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

compiled/facebook-www/ReactART-dev.modern.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20171,10 +20171,10 @@ __DEV__ &&
2017120171
(function () {
2017220172
var internals = {
2017320173
bundleType: 1,
20174-
version: "19.3.0-www-modern-46103596-20260305",
20174+
version: "19.3.0-www-modern-5e9eedb5-20260312",
2017520175
rendererPackageName: "react-art",
2017620176
currentDispatcherRef: ReactSharedInternals,
20177-
reconcilerVersion: "19.3.0-www-modern-46103596-20260305"
20177+
reconcilerVersion: "19.3.0-www-modern-5e9eedb5-20260312"
2017820178
};
2017920179
internals.overrideHookState = overrideHookState;
2018020180
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
@@ -20209,7 +20209,7 @@ __DEV__ &&
2020920209
exports.Shape = Shape;
2021020210
exports.Surface = Surface;
2021120211
exports.Text = Text;
20212-
exports.version = "19.3.0-www-modern-46103596-20260305";
20212+
exports.version = "19.3.0-www-modern-5e9eedb5-20260312";
2021320213
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
2021420214
"function" ===
2021520215
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)