Skip to content

Commit 48d420a

Browse files
committed
Track debug info from used thenables
1 parent 53d0794 commit 48d420a

File tree

1 file changed

+36
-0
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+36
-0
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {
11+
Thenable,
1112
ReactComponentInfo,
1213
ReactDebugInfo,
1314
ReactAsyncInfo,
@@ -3181,6 +3182,39 @@ export function attach(
31813182
}
31823183
}
31833184
3185+
function trackDebugInfoFromUsedThenables(fiber: Fiber): void {
3186+
// If a Fiber called use() in DEV mode then we may have collected _debugThenableState on
3187+
// the dependencies. If so, then this will contain the thenables passed to use().
3188+
// These won't have their debug info picked up by fiber._debugInfo since that just
3189+
// contains things suspending the children. We have to collect use() separately.
3190+
const dependencies = fiber.dependencies;
3191+
if (dependencies == null) {
3192+
return;
3193+
}
3194+
const thenableState = dependencies._debugThenableState;
3195+
if (thenableState == null) {
3196+
return;
3197+
}
3198+
// In DEV the thenableState is an inner object.
3199+
const usedThenables: any = thenableState.thenables || thenableState;
3200+
if (!Array.isArray(usedThenables)) {
3201+
return;
3202+
}
3203+
for (let i = 0; i < usedThenables.length; i++) {
3204+
const thenable: Thenable<mixed> = usedThenables[i];
3205+
const debugInfo = thenable._debugInfo;
3206+
if (debugInfo) {
3207+
for (let j = 0; j < debugInfo.length; j++) {
3208+
const debugEntry = debugInfo[i];
3209+
if (debugEntry.awaited) {
3210+
const asyncInfo: ReactAsyncInfo = (debugEntry: any);
3211+
insertSuspendedBy(asyncInfo);
3212+
}
3213+
}
3214+
}
3215+
}
3216+
}
3217+
31843218
function mountVirtualChildrenRecursively(
31853219
firstChild: Fiber,
31863220
lastChild: null | Fiber, // non-inclusive
@@ -3400,6 +3434,7 @@ export function attach(
34003434
}
34013435
34023436
trackDebugInfoFromLazyType(fiber);
3437+
trackDebugInfoFromUsedThenables(fiber);
34033438
34043439
if (fiber.tag === HostHoistable) {
34053440
const nearestInstance = reconcilingParent;
@@ -4231,6 +4266,7 @@ export function attach(
42314266
}
42324267
try {
42334268
trackDebugInfoFromLazyType(nextFiber);
4269+
trackDebugInfoFromUsedThenables(nextFiber);
42344270
42354271
if (
42364272
nextFiber.tag === HostHoistable &&

0 commit comments

Comments
 (0)