Skip to content

Commit edc20da

Browse files
committed
Move the context out of SuspenseComponent
1 parent d029d8c commit edc20da

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

packages/react-reconciler/src/ReactFiberSuspenseComponent.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010
import type {Fiber} from './ReactFiber';
1111
import type {ExpirationTime} from './ReactFiberExpirationTime';
1212

13-
import type {SuspenseContext} from './ReactFiberSuspenseContext';
14-
import {
15-
suspenseStackCursor,
16-
InvisibleParentSuspenseContext,
17-
hasSuspenseContext,
18-
} from './ReactFiberSuspenseContext';
19-
2013
export type SuspenseState = {|
2114
fallbackExpirationTime: ExpirationTime,
2215
|};
2316

24-
export function shouldCaptureSuspense(workInProgress: Fiber): boolean {
17+
export function shouldCaptureSuspense(
18+
workInProgress: Fiber,
19+
hasInvisibleParent: boolean,
20+
): boolean {
2521
// If it was the primary children that just suspended, capture and render the
2622
// fallback. Otherwise, don't capture and bubble to the next boundary.
2723
const nextState: SuspenseState | null = workInProgress.memoizedState;
@@ -39,12 +35,7 @@ export function shouldCaptureSuspense(workInProgress: Fiber): boolean {
3935
}
4036
// If it's a boundary we should avoid, then we prefer to bubble up to the
4137
// parent boundary if it is currently invisible.
42-
if (
43-
hasSuspenseContext(
44-
suspenseStackCursor.current,
45-
(InvisibleParentSuspenseContext: SuspenseContext),
46-
)
47-
) {
38+
if (hasInvisibleParent) {
4839
return false;
4940
}
5041
// If the parent is not able to handle it, we must handle it.

packages/react-reconciler/src/ReactFiberUnwindWork.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {ExpirationTime} from './ReactFiberExpirationTime';
1313
import type {CapturedValue} from './ReactCapturedValue';
1414
import type {Update} from './ReactUpdateQueue';
1515
import type {Thenable} from './ReactFiberScheduler';
16+
import type {SuspenseContext} from './ReactFiberSuspenseContext';
1617

1718
import {unstable_wrap as Schedule_tracing_wrap} from 'scheduler/tracing';
1819
import getComponentName from 'shared/getComponentName';
@@ -55,7 +56,12 @@ import {
5556
import {logError} from './ReactFiberCommitWork';
5657
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
5758
import {popHostContainer, popHostContext} from './ReactFiberHostContext';
58-
import {popSuspenseContext} from './ReactFiberSuspenseContext';
59+
import {
60+
suspenseStackCursor,
61+
InvisibleParentSuspenseContext,
62+
hasSuspenseContext,
63+
popSuspenseContext,
64+
} from './ReactFiberSuspenseContext';
5965
import {
6066
isContextProvider as isLegacyContextProvider,
6167
popContext as popLegacyContext,
@@ -207,15 +213,17 @@ function throwException(
207213

208214
checkForWrongSuspensePriorityInDEV(sourceFiber);
209215

210-
// TODO: If we're not in an invisible subtree, then we need to mark this render
211-
// as needing to suspend for longer to avoid showing this fallback state.
216+
let hasInvisibleParentBoundary = hasSuspenseContext(
217+
suspenseStackCursor.current,
218+
(InvisibleParentSuspenseContext: SuspenseContext),
219+
);
212220

213221
// Schedule the nearest Suspense to re-render the timed out view.
214222
let workInProgress = returnFiber;
215223
do {
216224
if (
217225
workInProgress.tag === SuspenseComponent &&
218-
shouldCaptureSuspense(workInProgress)
226+
shouldCaptureSuspense(workInProgress, hasInvisibleParentBoundary)
219227
) {
220228
// Found the nearest boundary.
221229

@@ -278,6 +286,13 @@ function throwException(
278286

279287
workInProgress.effectTag |= ShouldCapture;
280288
workInProgress.expirationTime = renderExpirationTime;
289+
290+
if (!hasInvisibleParentBoundary) {
291+
// TODO: If we're not in an invisible subtree, then we need to mark this render
292+
// pass as needing to suspend for longer to avoid showing this fallback state.
293+
// We could do it here or when we render the fallback.
294+
}
295+
281296
return;
282297
} else if (
283298
enableSuspenseServerRenderer &&

0 commit comments

Comments
 (0)