Skip to content

Commit d74ed5b

Browse files
committed
[DevTools] Handle fallback unmount in Suspense update path
1 parent 3da3e9e commit d74ed5b

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,12 @@ describe('Store', () => {
27672767
resolveContent();
27682768
});
27692769

2770-
expect(store).toMatchInlineSnapshot();
2770+
expect(store).toMatchInlineSnapshot(`
2771+
[root]
2772+
▾ <Suspense name="content">
2773+
<Component key="content">
2774+
[shell]
2775+
<Suspense name="content" rects={[{x:1,y:2,width:4,height:1}]}>
2776+
`);
27712777
});
27722778
});

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,34 +4736,39 @@ export function attach(
47364736
);
47374737
47384738
shouldMeasureSuspenseNode = false;
4739-
if (nextFallbackFiber !== null) {
4739+
if (prevFallbackFiber !== null || nextFallbackFiber !== null) {
47404740
const fallbackStashedSuspenseParent = reconcilingParentSuspenseNode;
47414741
const fallbackStashedSuspensePrevious =
47424742
previouslyReconciledSiblingSuspenseNode;
47434743
const fallbackStashedSuspenseRemaining =
47444744
remainingReconcilingChildrenSuspenseNodes;
47454745
// Next, we'll pop back out of the SuspenseNode that we added above and now we'll
4746-
// reconcile the fallback, reconciling anything by inserting into the parent SuspenseNode.
4746+
// reconcile the fallback, reconciling anything in the context of the parent SuspenseNode.
47474747
// Since the fallback conceptually blocks the parent.
47484748
reconcilingParentSuspenseNode = stashedSuspenseParent;
47494749
previouslyReconciledSiblingSuspenseNode = stashedSuspensePrevious;
47504750
remainingReconcilingChildrenSuspenseNodes = stashedSuspenseRemaining;
47514751
try {
4752-
updateFlags |= updateVirtualChildrenRecursively(
4753-
nextFallbackFiber,
4754-
null,
4755-
prevFallbackFiber,
4756-
traceNearestHostComponentUpdate,
4757-
0,
4758-
);
4752+
if (nextFallbackFiber === null) {
4753+
unmountRemainingChildren();
4754+
} else {
4755+
updateFlags |= updateVirtualChildrenRecursively(
4756+
nextFallbackFiber,
4757+
null,
4758+
prevFallbackFiber,
4759+
traceNearestHostComponentUpdate,
4760+
0,
4761+
);
4762+
}
47594763
} finally {
47604764
reconcilingParentSuspenseNode = fallbackStashedSuspenseParent;
47614765
previouslyReconciledSiblingSuspenseNode =
47624766
fallbackStashedSuspensePrevious;
47634767
remainingReconcilingChildrenSuspenseNodes =
47644768
fallbackStashedSuspenseRemaining;
47654769
}
4766-
} else if (nextFiber.memoizedState === null) {
4770+
}
4771+
if (nextFiber.memoizedState === null) {
47674772
// Measure this Suspense node in case it changed. We don't update the rect while
47684773
// we're inside a disconnected subtree nor if we are the Suspense boundary that
47694774
// is suspended. This lets us keep the rectangle of the displayed content while

0 commit comments

Comments
 (0)