Skip to content

Commit 72965f3

Browse files
authored
[DevTools] Restore reconciling Suspense stack after fallback was reconciled (#34168)
1 parent 594fb5e commit 72965f3

File tree

1 file changed

+37
-33
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+37
-33
lines changed

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

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,7 +4162,7 @@ export function attach(
41624162
const stashedSuspenseParent = reconcilingParentSuspenseNode;
41634163
const stashedSuspensePrevious = previouslyReconciledSiblingSuspenseNode;
41644164
const stashedSuspenseRemaining = remainingReconcilingChildrenSuspenseNodes;
4165-
let shouldPopSuspenseNode = false;
4165+
let shouldMeasureSuspenseNode = false;
41664166
let previousSuspendedBy = null;
41674167
if (fiberInstance !== null) {
41684168
previousSuspendedBy = fiberInstance.suspendedBy;
@@ -4192,7 +4192,7 @@ export function attach(
41924192
previouslyReconciledSiblingSuspenseNode = null;
41934193
remainingReconcilingChildrenSuspenseNodes = suspenseNode.firstChild;
41944194
suspenseNode.firstChild = null;
4195-
shouldPopSuspenseNode = true;
4195+
shouldMeasureSuspenseNode = true;
41964196
}
41974197
}
41984198
try {
@@ -4379,38 +4379,40 @@ export function attach(
43794379
0,
43804380
);
43814381
4382-
// Next, we'll pop back out of the SuspenseNode that we added above and now we'll
4383-
// reconcile the fallback, reconciling anything by inserting into the parent SuspenseNode.
4384-
// Since the fallback conceptually blocks the parent.
4385-
reconcilingParentSuspenseNode = stashedSuspenseParent;
4386-
previouslyReconciledSiblingSuspenseNode = stashedSuspensePrevious;
4387-
remainingReconcilingChildrenSuspenseNodes = stashedSuspenseRemaining;
4388-
shouldPopSuspenseNode = false;
4382+
shouldMeasureSuspenseNode = false;
43894383
if (nextFallbackFiber !== null) {
4390-
updateFlags |= updateVirtualChildrenRecursively(
4391-
nextFallbackFiber,
4392-
null,
4393-
prevFallbackFiber,
4394-
traceNearestHostComponentUpdate,
4395-
0,
4396-
);
4397-
} else if (
4398-
nextFiber.memoizedState === null &&
4399-
fiberInstance.suspenseNode !== null
4400-
) {
4401-
if (!isInDisconnectedSubtree) {
4402-
// Measure this Suspense node in case it changed. We don't update the rect while
4403-
// we're inside a disconnected subtree nor if we are the Suspense boundary that
4404-
// is suspended. This lets us keep the rectangle of the displayed content while
4405-
// we're suspended to visualize the resulting state.
4406-
const suspenseNode = fiberInstance.suspenseNode;
4407-
const prevRects = suspenseNode.rects;
4408-
const nextRects = measureInstance(fiberInstance);
4409-
if (!areEqualRects(prevRects, nextRects)) {
4410-
suspenseNode.rects = nextRects;
4411-
recordSuspenseResize(suspenseNode);
4412-
}
4384+
const fallbackStashedSuspenseParent = reconcilingParentSuspenseNode;
4385+
const fallbackStashedSuspensePrevious =
4386+
previouslyReconciledSiblingSuspenseNode;
4387+
const fallbackStashedSuspenseRemaining =
4388+
remainingReconcilingChildrenSuspenseNodes;
4389+
// Next, we'll pop back out of the SuspenseNode that we added above and now we'll
4390+
// reconcile the fallback, reconciling anything by inserting into the parent SuspenseNode.
4391+
// Since the fallback conceptually blocks the parent.
4392+
reconcilingParentSuspenseNode = stashedSuspenseParent;
4393+
previouslyReconciledSiblingSuspenseNode = stashedSuspensePrevious;
4394+
remainingReconcilingChildrenSuspenseNodes = stashedSuspenseRemaining;
4395+
try {
4396+
updateFlags |= updateVirtualChildrenRecursively(
4397+
nextFallbackFiber,
4398+
null,
4399+
prevFallbackFiber,
4400+
traceNearestHostComponentUpdate,
4401+
0,
4402+
);
4403+
} finally {
4404+
reconcilingParentSuspenseNode = fallbackStashedSuspenseParent;
4405+
previouslyReconciledSiblingSuspenseNode =
4406+
fallbackStashedSuspensePrevious;
4407+
remainingReconcilingChildrenSuspenseNodes =
4408+
fallbackStashedSuspenseRemaining;
44134409
}
4410+
} else if (nextFiber.memoizedState === null) {
4411+
// Measure this Suspense node in case it changed. We don't update the rect while
4412+
// we're inside a disconnected subtree nor if we are the Suspense boundary that
4413+
// is suspended. This lets us keep the rectangle of the displayed content while
4414+
// we're suspended to visualize the resulting state.
4415+
shouldMeasureSuspenseNode = !isInDisconnectedSubtree;
44144416
}
44154417
} else {
44164418
// Common case: Primary -> Primary.
@@ -4519,7 +4521,7 @@ export function attach(
45194521
reconcilingParent = stashedParent;
45204522
previouslyReconciledSibling = stashedPrevious;
45214523
remainingReconcilingChildren = stashedRemaining;
4522-
if (shouldPopSuspenseNode) {
4524+
if (shouldMeasureSuspenseNode) {
45234525
if (
45244526
!isInDisconnectedSubtree &&
45254527
reconcilingParentSuspenseNode !== null
@@ -4535,6 +4537,8 @@ export function attach(
45354537
recordSuspenseResize(suspenseNode);
45364538
}
45374539
}
4540+
}
4541+
if (fiberInstance.suspenseNode !== null) {
45384542
reconcilingParentSuspenseNode = stashedSuspenseParent;
45394543
previouslyReconciledSiblingSuspenseNode = stashedSuspensePrevious;
45404544
remainingReconcilingChildrenSuspenseNodes = stashedSuspenseRemaining;

0 commit comments

Comments
 (0)