Skip to content

Commit f4b1e21

Browse files
committed
Track debug info from used thenables
1 parent 3958d5d commit f4b1e21

File tree

1 file changed

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

1 file changed

+38
-0
lines changed

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

Lines changed: 38 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,
@@ -3045,6 +3046,39 @@ export function attach(
30453046
return null;
30463047
}
30473048
3049+
function trackDebugInfoFromUsedThenables(fiber: Fiber): void {
3050+
// If a Fiber called use() in DEV mode then we may have collected _debugThenableState on
3051+
// the dependencies. If so, then this will contain the thenables passed to use().
3052+
// These won't have their debug info picked up by fiber._debugInfo since that just
3053+
// contains things suspending the children. We have to collect use() separately.
3054+
const dependencies = fiber.dependencies;
3055+
if (dependencies == null) {
3056+
return;
3057+
}
3058+
const thenableState = dependencies._debugThenableState;
3059+
if (thenableState == null) {
3060+
return;
3061+
}
3062+
// In DEV the thenableState is an inner object.
3063+
const usedThenables: any = thenableState.thenables || thenableState;
3064+
if (!Array.isArray(usedThenables)) {
3065+
return;
3066+
}
3067+
for (let i = 0; i < usedThenables.length; i++) {
3068+
const thenable: Thenable<mixed> = usedThenables[i];
3069+
const debugInfo = thenable._debugInfo;
3070+
if (debugInfo) {
3071+
for (let j = 0; j < debugInfo.length; j++) {
3072+
const debugEntry = debugInfo[i];
3073+
if (debugEntry.awaited) {
3074+
const asyncInfo: ReactAsyncInfo = (debugEntry: any);
3075+
insertSuspendedBy(asyncInfo);
3076+
}
3077+
}
3078+
}
3079+
}
3080+
}
3081+
30483082
function mountVirtualChildrenRecursively(
30493083
firstChild: Fiber,
30503084
lastChild: null | Fiber, // non-inclusive
@@ -3262,6 +3296,8 @@ export function attach(
32623296
// because we don't want to highlight every host node inside of a newly mounted subtree.
32633297
}
32643298
3299+
trackDebugInfoFromUsedThenables(fiber);
3300+
32653301
if (fiber.tag === HostHoistable) {
32663302
const nearestInstance = reconcilingParent;
32673303
if (nearestInstance === null) {
@@ -4040,6 +4076,8 @@ export function attach(
40404076
}
40414077
}
40424078
try {
4079+
trackDebugInfoFromUsedThenables(nextFiber);
4080+
40434081
if (
40444082
nextFiber.tag === HostHoistable &&
40454083
prevFiber.memoizedState !== nextFiber.memoizedState

0 commit comments

Comments
 (0)