Skip to content

Commit 21137eb

Browse files
committed
[DevTools] Exclude Suspense boundaries in hidden Activity
1 parent 3d2b72d commit 21137eb

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

packages/react-devtools-shared/src/__tests__/store-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,6 @@ describe('Store', () => {
31993199
<Activity>
32003200
<Suspense name="outer-suspense">
32013201
[suspense-root] rects={[{x:1,y:2,width:15,height:1}, {x:1,y:2,width:15,height:1}]}
3202-
<Suspense name="inside-activity" rects={[{x:1,y:2,width:15,height:1}]}>
32033202
<Suspense name="outer-suspense" rects={[{x:1,y:2,width:15,height:1}]}>
32043203
<Suspense name="inner-suspense" rects={[{x:1,y:2,width:15,height:1}]}>
32053204
`);

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,20 +3136,36 @@ export function attach(
31363136
function isHiddenOffscreen(fiber: Fiber): boolean {
31373137
switch (fiber.tag) {
31383138
case LegacyHiddenComponent:
3139-
// fallthrough since all published implementations currently implement the same state as Offscreen.
31403139
case OffscreenComponent:
31413140
return fiber.memoizedState !== null;
31423141
default:
31433142
return false;
31443143
}
31453144
}
31463145
3146+
/**
3147+
* Offscreen of resuspended Suspense
3148+
*/
3149+
function isResuspendedOffscreen(fiber: Fiber): boolean {
3150+
switch (fiber.tag) {
3151+
case LegacyHiddenComponent:
3152+
case OffscreenComponent:
3153+
return (
3154+
fiber.memoizedState !== null &&
3155+
fiber.return !== null &&
3156+
fiber.return.tag === SuspenseComponent
3157+
);
3158+
default:
3159+
return false;
3160+
}
3161+
}
3162+
31473163
function unmountRemainingChildren() {
31483164
if (
31493165
reconcilingParent !== null &&
31503166
(reconcilingParent.kind === FIBER_INSTANCE ||
31513167
reconcilingParent.kind === FILTERED_FIBER_INSTANCE) &&
3152-
isHiddenOffscreen(reconcilingParent.data) &&
3168+
isResuspendedOffscreen(reconcilingParent.data) &&
31533169
!isInDisconnectedSubtree
31543170
) {
31553171
// This is a hidden offscreen, we need to execute this in the context of a disconnected subtree.
@@ -4027,6 +4043,9 @@ export function attach(
40274043
}
40284044
40294045
if (isHiddenOffscreen(fiber)) {
4046+
// hidden Activity is noisy.
4047+
// Including it may show overlapping Suspense rects
4048+
} else if (isResuspendedOffscreen(fiber)) {
40304049
// If an Offscreen component is hidden, mount its children as disconnected.
40314050
const stashedDisconnected = isInDisconnectedSubtree;
40324051
isInDisconnectedSubtree = true;
@@ -4981,6 +5000,8 @@ export function attach(
49815000
49825001
const prevWasHidden = isHiddenOffscreen(prevFiber);
49835002
const nextIsHidden = isHiddenOffscreen(nextFiber);
5003+
const prevWasSuspended = isResuspendedOffscreen(prevFiber);
5004+
const nextIsSuspended = isResuspendedOffscreen(nextFiber);
49845005
49855006
if (isLegacySuspense) {
49865007
if (
@@ -5058,8 +5079,8 @@ export function attach(
50585079
);
50595080
updateFlags |= ShouldResetChildren | ShouldResetSuspenseChildren;
50605081
}
5061-
} else if (nextIsHidden) {
5062-
if (!prevWasHidden) {
5082+
} else if (nextIsSuspended) {
5083+
if (!prevWasSuspended) {
50635084
// We're hiding the children. Disconnect them from the front end but keep state.
50645085
if (fiberInstance !== null && !isInDisconnectedSubtree) {
50655086
disconnectChildrenRecursively(remainingReconcilingChildren);
@@ -5077,7 +5098,7 @@ export function attach(
50775098
} finally {
50785099
isInDisconnectedSubtree = stashedDisconnected;
50795100
}
5080-
} else if (prevWasHidden && !nextIsHidden) {
5101+
} else if (prevWasSuspended && !nextIsSuspended) {
50815102
// We're revealing the hidden children. We now need to update them to the latest state.
50825103
// We do this while still in the disconnected state and then we reconnect the new ones.
50835104
// This avoids reconnecting things that are about to be removed anyway.
@@ -5103,6 +5124,11 @@ export function attach(
51035124
// Children may have reordered while they were hidden.
51045125
updateFlags |= ShouldResetChildren | ShouldResetSuspenseChildren;
51055126
}
5127+
} else if (nextIsHidden) {
5128+
if (!prevWasHidden) {
5129+
// We're hiding the children. Remove them from the Frontend
5130+
unmountRemainingChildren();
5131+
}
51065132
} else if (
51075133
nextFiber.tag === SuspenseComponent &&
51085134
OffscreenComponent !== -1 &&
@@ -5259,7 +5285,7 @@ export function attach(
52595285
// We need to crawl the subtree for closest non-filtered Fibers
52605286
// so that we can display them in a flat children set.
52615287
if (fiberInstance !== null && fiberInstance.kind === FIBER_INSTANCE) {
5262-
if (!nextIsHidden && !isInDisconnectedSubtree) {
5288+
if (!nextIsSuspended && !isInDisconnectedSubtree) {
52635289
recordResetChildren(fiberInstance);
52645290
}
52655291
@@ -5335,7 +5361,7 @@ export function attach(
53355361
if (
53365362
(child.kind === FIBER_INSTANCE ||
53375363
child.kind === FILTERED_FIBER_INSTANCE) &&
5338-
isHiddenOffscreen(child.data)
5364+
isResuspendedOffscreen(child.data)
53395365
) {
53405366
// This instance's children are already disconnected.
53415367
} else {
@@ -5364,7 +5390,7 @@ export function attach(
53645390
if (
53655391
(child.kind === FIBER_INSTANCE ||
53665392
child.kind === FILTERED_FIBER_INSTANCE) &&
5367-
isHiddenOffscreen(child.data)
5393+
isResuspendedOffscreen(child.data)
53685394
) {
53695395
// This instance's children should remain disconnected.
53705396
} else {

0 commit comments

Comments
 (0)