Skip to content

Commit 8276ad7

Browse files
committed
[Fiber] Instrument the lazy initializer thenable in all cases (facebook#35521)
When a lazy element or component is initialized a thenable is returned which was only be conditionally instrumented in dev when asyncDebugInfo was enabled. When instrumented these thenables can be used in conjunction with the SuspendOnImmediate optimization where if a thenable resolves before the stack unwinds we can continue rendering from the last suspended fiber. Without this change a recent fix to the useId implementation cannot be easily tested in production because this optimization pathway isn't available to regular React.lazy thenables. To land the prior PR I changed the thenables to a custom type so I could instrument manually in the test. WIth this change we can just use a regular Promise since ReactLazy will instrument in all environments/flags now DiffTrain build for [db71391](facebook@db71391)
1 parent ad8d5c9 commit 8276ad7

34 files changed

+3483
-3163
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4a3d993e52fd6bcadd9c3029c75df3c22684f69c
1+
db71391c5c70dc113560d1c23d0b6548604d827f
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4a3d993e52fd6bcadd9c3029c75df3c22684f69c
1+
db71391c5c70dc113560d1c23d0b6548604d827f

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,10 @@ __DEV__ &&
551551
var thenable = ioInfo();
552552
thenable.then(
553553
function (moduleObject) {
554-
if (0 === payload._status || -1 === payload._status)
555-
if (
556-
((payload._status = 1),
557-
(payload._result = moduleObject),
558-
enableAsyncDebugInfo)
559-
) {
554+
if (0 === payload._status || -1 === payload._status) {
555+
payload._status = 1;
556+
payload._result = moduleObject;
557+
if (enableAsyncDebugInfo) {
560558
var _ioInfo = payload._ioInfo;
561559
if (null != _ioInfo) {
562560
_ioInfo.end = performance.now();
@@ -566,28 +564,28 @@ __DEV__ &&
566564
_ioInfo.value.status = "fulfilled";
567565
_ioInfo.value.value = debugValue;
568566
}
569-
void 0 === thenable.status &&
570-
((thenable.status = "fulfilled"),
571-
(thenable.value = moduleObject));
572567
}
568+
void 0 === thenable.status &&
569+
((thenable.status = "fulfilled"),
570+
(thenable.value = moduleObject));
571+
}
573572
},
574573
function (error) {
575-
if (0 === payload._status || -1 === payload._status)
576-
if (
577-
((payload._status = 2),
578-
(payload._result = error),
579-
enableAsyncDebugInfo)
580-
) {
574+
if (0 === payload._status || -1 === payload._status) {
575+
payload._status = 2;
576+
payload._result = error;
577+
if (enableAsyncDebugInfo) {
581578
var _ioInfo2 = payload._ioInfo;
582579
null != _ioInfo2 &&
583580
((_ioInfo2.end = performance.now()),
584581
_ioInfo2.value.then(noop, noop),
585582
rejectDebugValue(error),
586583
(_ioInfo2.value.status = "rejected"),
587584
(_ioInfo2.value.reason = error));
588-
void 0 === thenable.status &&
589-
((thenable.status = "rejected"), (thenable.reason = error));
590585
}
586+
void 0 === thenable.status &&
587+
((thenable.status = "rejected"), (thenable.reason = error));
588+
}
591589
}
592590
);
593591
if (
@@ -1499,7 +1497,7 @@ __DEV__ &&
14991497
exports.useTransition = function () {
15001498
return resolveDispatcher().useTransition();
15011499
};
1502-
exports.version = "19.3.0-www-classic-4a3d993e-20260114";
1500+
exports.version = "19.3.0-www-classic-db71391c-20260115";
15031501
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15041502
"function" ===
15051503
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,10 @@ __DEV__ &&
551551
var thenable = ioInfo();
552552
thenable.then(
553553
function (moduleObject) {
554-
if (0 === payload._status || -1 === payload._status)
555-
if (
556-
((payload._status = 1),
557-
(payload._result = moduleObject),
558-
enableAsyncDebugInfo)
559-
) {
554+
if (0 === payload._status || -1 === payload._status) {
555+
payload._status = 1;
556+
payload._result = moduleObject;
557+
if (enableAsyncDebugInfo) {
560558
var _ioInfo = payload._ioInfo;
561559
if (null != _ioInfo) {
562560
_ioInfo.end = performance.now();
@@ -566,28 +564,28 @@ __DEV__ &&
566564
_ioInfo.value.status = "fulfilled";
567565
_ioInfo.value.value = debugValue;
568566
}
569-
void 0 === thenable.status &&
570-
((thenable.status = "fulfilled"),
571-
(thenable.value = moduleObject));
572567
}
568+
void 0 === thenable.status &&
569+
((thenable.status = "fulfilled"),
570+
(thenable.value = moduleObject));
571+
}
573572
},
574573
function (error) {
575-
if (0 === payload._status || -1 === payload._status)
576-
if (
577-
((payload._status = 2),
578-
(payload._result = error),
579-
enableAsyncDebugInfo)
580-
) {
574+
if (0 === payload._status || -1 === payload._status) {
575+
payload._status = 2;
576+
payload._result = error;
577+
if (enableAsyncDebugInfo) {
581578
var _ioInfo2 = payload._ioInfo;
582579
null != _ioInfo2 &&
583580
((_ioInfo2.end = performance.now()),
584581
_ioInfo2.value.then(noop, noop),
585582
rejectDebugValue(error),
586583
(_ioInfo2.value.status = "rejected"),
587584
(_ioInfo2.value.reason = error));
588-
void 0 === thenable.status &&
589-
((thenable.status = "rejected"), (thenable.reason = error));
590585
}
586+
void 0 === thenable.status &&
587+
((thenable.status = "rejected"), (thenable.reason = error));
588+
}
591589
}
592590
);
593591
if (
@@ -1499,7 +1497,7 @@ __DEV__ &&
14991497
exports.useTransition = function () {
15001498
return resolveDispatcher().useTransition();
15011499
};
1502-
exports.version = "19.3.0-www-modern-4a3d993e-20260114";
1500+
exports.version = "19.3.0-www-modern-db71391c-20260115";
15031501
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
15041502
"function" ===
15051503
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,27 @@ function mapChildren(children, func, context) {
288288
}
289289
function lazyInitializer(payload) {
290290
if (-1 === payload._status) {
291-
var ctor = payload._result;
292-
ctor = ctor();
293-
ctor.then(
291+
var ctor = payload._result,
292+
thenable = ctor();
293+
thenable.then(
294294
function (moduleObject) {
295295
if (0 === payload._status || -1 === payload._status)
296-
(payload._status = 1), (payload._result = moduleObject);
296+
(payload._status = 1),
297+
(payload._result = moduleObject),
298+
void 0 === thenable.status &&
299+
((thenable.status = "fulfilled"),
300+
(thenable.value = moduleObject));
297301
},
298302
function (error) {
299303
if (0 === payload._status || -1 === payload._status)
300-
(payload._status = 2), (payload._result = error);
304+
(payload._status = 2),
305+
(payload._result = error),
306+
void 0 === thenable.status &&
307+
((thenable.status = "rejected"), (thenable.reason = error));
301308
}
302309
);
303-
-1 === payload._status && ((payload._status = 0), (payload._result = ctor));
310+
-1 === payload._status &&
311+
((payload._status = 0), (payload._result = thenable));
304312
}
305313
if (1 === payload._status) return payload._result.default;
306314
throw payload._result;
@@ -606,4 +614,4 @@ exports.useSyncExternalStore = function (
606614
exports.useTransition = function () {
607615
return ReactSharedInternals.H.useTransition();
608616
};
609-
exports.version = "19.3.0-www-classic-4a3d993e-20260114";
617+
exports.version = "19.3.0-www-classic-db71391c-20260115";

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,27 @@ function mapChildren(children, func, context) {
288288
}
289289
function lazyInitializer(payload) {
290290
if (-1 === payload._status) {
291-
var ctor = payload._result;
292-
ctor = ctor();
293-
ctor.then(
291+
var ctor = payload._result,
292+
thenable = ctor();
293+
thenable.then(
294294
function (moduleObject) {
295295
if (0 === payload._status || -1 === payload._status)
296-
(payload._status = 1), (payload._result = moduleObject);
296+
(payload._status = 1),
297+
(payload._result = moduleObject),
298+
void 0 === thenable.status &&
299+
((thenable.status = "fulfilled"),
300+
(thenable.value = moduleObject));
297301
},
298302
function (error) {
299303
if (0 === payload._status || -1 === payload._status)
300-
(payload._status = 2), (payload._result = error);
304+
(payload._status = 2),
305+
(payload._result = error),
306+
void 0 === thenable.status &&
307+
((thenable.status = "rejected"), (thenable.reason = error));
301308
}
302309
);
303-
-1 === payload._status && ((payload._status = 0), (payload._result = ctor));
310+
-1 === payload._status &&
311+
((payload._status = 0), (payload._result = thenable));
304312
}
305313
if (1 === payload._status) return payload._result.default;
306314
throw payload._result;
@@ -606,4 +614,4 @@ exports.useSyncExternalStore = function (
606614
exports.useTransition = function () {
607615
return ReactSharedInternals.H.useTransition();
608616
};
609-
exports.version = "19.3.0-www-modern-4a3d993e-20260114";
617+
exports.version = "19.3.0-www-modern-db71391c-20260115";

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,27 @@ function mapChildren(children, func, context) {
292292
}
293293
function lazyInitializer(payload) {
294294
if (-1 === payload._status) {
295-
var ctor = payload._result;
296-
ctor = ctor();
297-
ctor.then(
295+
var ctor = payload._result,
296+
thenable = ctor();
297+
thenable.then(
298298
function (moduleObject) {
299299
if (0 === payload._status || -1 === payload._status)
300-
(payload._status = 1), (payload._result = moduleObject);
300+
(payload._status = 1),
301+
(payload._result = moduleObject),
302+
void 0 === thenable.status &&
303+
((thenable.status = "fulfilled"),
304+
(thenable.value = moduleObject));
301305
},
302306
function (error) {
303307
if (0 === payload._status || -1 === payload._status)
304-
(payload._status = 2), (payload._result = error);
308+
(payload._status = 2),
309+
(payload._result = error),
310+
void 0 === thenable.status &&
311+
((thenable.status = "rejected"), (thenable.reason = error));
305312
}
306313
);
307-
-1 === payload._status && ((payload._status = 0), (payload._result = ctor));
314+
-1 === payload._status &&
315+
((payload._status = 0), (payload._result = thenable));
308316
}
309317
if (1 === payload._status) return payload._result.default;
310318
throw payload._result;
@@ -610,7 +618,7 @@ exports.useSyncExternalStore = function (
610618
exports.useTransition = function () {
611619
return ReactSharedInternals.H.useTransition();
612620
};
613-
exports.version = "19.3.0-www-classic-4a3d993e-20260114";
621+
exports.version = "19.3.0-www-classic-db71391c-20260115";
614622
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
615623
"function" ===
616624
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,19 +292,27 @@ function mapChildren(children, func, context) {
292292
}
293293
function lazyInitializer(payload) {
294294
if (-1 === payload._status) {
295-
var ctor = payload._result;
296-
ctor = ctor();
297-
ctor.then(
295+
var ctor = payload._result,
296+
thenable = ctor();
297+
thenable.then(
298298
function (moduleObject) {
299299
if (0 === payload._status || -1 === payload._status)
300-
(payload._status = 1), (payload._result = moduleObject);
300+
(payload._status = 1),
301+
(payload._result = moduleObject),
302+
void 0 === thenable.status &&
303+
((thenable.status = "fulfilled"),
304+
(thenable.value = moduleObject));
301305
},
302306
function (error) {
303307
if (0 === payload._status || -1 === payload._status)
304-
(payload._status = 2), (payload._result = error);
308+
(payload._status = 2),
309+
(payload._result = error),
310+
void 0 === thenable.status &&
311+
((thenable.status = "rejected"), (thenable.reason = error));
305312
}
306313
);
307-
-1 === payload._status && ((payload._status = 0), (payload._result = ctor));
314+
-1 === payload._status &&
315+
((payload._status = 0), (payload._result = thenable));
308316
}
309317
if (1 === payload._status) return payload._result.default;
310318
throw payload._result;
@@ -610,7 +618,7 @@ exports.useSyncExternalStore = function (
610618
exports.useTransition = function () {
611619
return ReactSharedInternals.H.useTransition();
612620
};
613-
exports.version = "19.3.0-www-modern-4a3d993e-20260114";
621+
exports.version = "19.3.0-www-modern-db71391c-20260115";
614622
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
615623
"function" ===
616624
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&

0 commit comments

Comments
 (0)