@@ -27,7 +27,6 @@ import type { |
27 | 27 | SuspenseState, |
28 | 28 | SuspenseListRenderState, |
29 | 29 | } from './ReactFiberSuspenseComponent.new'; |
30 | | -import type {SuspenseContext} from './ReactFiberSuspenseContext.new'; |
31 | 30 | import type {OffscreenState} from './ReactFiberOffscreenComponent'; |
32 | 31 | import type {Cache} from './ReactFiberCacheComponent.new'; |
33 | 32 | import { |
@@ -109,14 +108,17 @@ import { |
109 | 108 | } from './ReactFiberHostContext.new'; |
110 | 109 | import { |
111 | 110 | suspenseStackCursor, |
112 | | - InvisibleParentSuspenseContext, |
113 | | - hasSuspenseContext, |
114 | | - popSuspenseContext, |
115 | | - pushSuspenseContext, |
116 | | - setShallowSuspenseContext, |
| 111 | + popSuspenseListContext, |
| 112 | + popSuspenseHandler, |
| 113 | + pushSuspenseListContext, |
| 114 | + setShallowSuspenseListContext, |
117 | 115 | ForceSuspenseFallback, |
118 | | - setDefaultShallowSuspenseContext, |
| 116 | + setDefaultShallowSuspenseListContext, |
119 | 117 | } from './ReactFiberSuspenseContext.new'; |
| 118 | +import { |
| 119 | + popHiddenContext, |
| 120 | + isCurrentTreeHidden, |
| 121 | +} from './ReactFiberHiddenContext.new'; |
120 | 122 | import {findFirstSuspended} from './ReactFiberSuspenseComponent.new'; |
121 | 123 | import { |
122 | 124 | isContextProvider as isLegacyContextProvider, |
@@ -146,9 +148,7 @@ import { |
146 | 148 | renderDidSuspend, |
147 | 149 | renderDidSuspendDelayIfPossible, |
148 | 150 | renderHasNotSuspendedYet, |
149 | | - popRenderLanes, |
150 | 151 | getRenderTargetTime, |
151 | | - subtreeRenderLanes, |
152 | 152 | getWorkInProgressTransitions, |
153 | 153 | } from './ReactFiberWorkLoop.new'; |
154 | 154 | import { |
@@ -1077,7 +1077,7 @@ function completeWork( |
1077 | 1077 | return null; |
1078 | 1078 | } |
1079 | 1079 | case SuspenseComponent: { |
1080 | | - popSuspenseContext(workInProgress); |
| 1080 | + popSuspenseHandler(workInProgress); |
1081 | 1081 | const nextState: null | SuspenseState = workInProgress.memoizedState; |
1082 | 1082 |
|
1083 | 1083 | // Special path for dehydrated boundaries. We may eventually move this |
@@ -1186,25 +1186,23 @@ function completeWork( |
1186 | 1186 | // If this render already had a ping or lower pri updates, |
1187 | 1187 | // and this is the first time we know we're going to suspend we |
1188 | 1188 | // should be able to immediately restart from within throwException. |
1189 | | - const hasInvisibleChildContext = |
1190 | | - current === null && |
1191 | | - (workInProgress.memoizedProps.unstable_avoidThisFallback !== |
1192 | | - true || |
1193 | | - !enableSuspenseAvoidThisFallback); |
1194 | | - if ( |
1195 | | - hasInvisibleChildContext || |
1196 | | - hasSuspenseContext( |
1197 | | - suspenseStackCursor.current, |
1198 | | - (InvisibleParentSuspenseContext: SuspenseContext), |
1199 | | - ) |
1200 | | - ) { |
1201 | | - // If this was in an invisible tree or a new render, then showing |
1202 | | - // this boundary is ok. |
1203 | | - renderDidSuspend(); |
1204 | | - } else { |
1205 | | - // Otherwise, we're going to have to hide content so we should |
1206 | | - // suspend for longer if possible. |
| 1189 | + |
| 1190 | + // Check if this is a "bad" fallback state or a good one. A bad |
| 1191 | + // fallback state is one that we only show as a last resort; if this |
| 1192 | + // is a transition, we'll block it from displaying, and wait for |
| 1193 | + // more data to arrive. |
| 1194 | + const isBadFallback = |
| 1195 | + // It's bad to switch to a fallback if content is already visible |
| 1196 | + (current !== null && !prevDidTimeout && !isCurrentTreeHidden()) || |
| 1197 | + // Experimental: Some fallbacks are always bad |
| 1198 | + (enableSuspenseAvoidThisFallback && |
| 1199 | + workInProgress.memoizedProps.unstable_avoidThisFallback === |
| 1200 | + true); |
| 1201 | + |
| 1202 | + if (isBadFallback) { |
1207 | 1203 | renderDidSuspendDelayIfPossible(); |
| 1204 | + } else { |
| 1205 | + renderDidSuspend(); |
1208 | 1206 | } |
1209 | 1207 | } |
1210 | 1208 | } |
@@ -1266,7 +1264,7 @@ function completeWork( |
1266 | 1264 | return null; |
1267 | 1265 | } |
1268 | 1266 | case SuspenseListComponent: { |
1269 | | - popSuspenseContext(workInProgress); |
| 1267 | + popSuspenseListContext(workInProgress); |
1270 | 1268 |
|
1271 | 1269 | const renderState: null | SuspenseListRenderState = |
1272 | 1270 | workInProgress.memoizedState; |
@@ -1332,11 +1330,11 @@ function completeWork( |
1332 | 1330 | workInProgress.subtreeFlags = NoFlags; |
1333 | 1331 | resetChildFibers(workInProgress, renderLanes); |
1334 | 1332 |
|
1335 | | - // Set up the Suspense Context to force suspense and immediately |
1336 | | - // rerender the children. |
1337 | | - pushSuspenseContext( |
| 1333 | + // Set up the Suspense List Context to force suspense and |
| 1334 | + // immediately rerender the children. |
| 1335 | + pushSuspenseListContext( |
1338 | 1336 | workInProgress, |
1339 | | - setShallowSuspenseContext( |
| 1337 | + setShallowSuspenseListContext( |
1340 | 1338 | suspenseStackCursor.current, |
1341 | 1339 | ForceSuspenseFallback, |
1342 | 1340 | ), |
@@ -1459,14 +1457,16 @@ function completeWork( |
1459 | 1457 | // setting it the first time we go from not suspended to suspended. |
1460 | 1458 | let suspenseContext = suspenseStackCursor.current; |
1461 | 1459 | if (didSuspendAlready) { |
1462 | | - suspenseContext = setShallowSuspenseContext( |
| 1460 | + suspenseContext = setShallowSuspenseListContext( |
1463 | 1461 | suspenseContext, |
1464 | 1462 | ForceSuspenseFallback, |
1465 | 1463 | ); |
1466 | 1464 | } else { |
1467 | | - suspenseContext = setDefaultShallowSuspenseContext(suspenseContext); |
| 1465 | + suspenseContext = setDefaultShallowSuspenseListContext( |
| 1466 | + suspenseContext, |
| 1467 | + ); |
1468 | 1468 | } |
1469 | | - pushSuspenseContext(workInProgress, suspenseContext); |
| 1469 | + pushSuspenseListContext(workInProgress, suspenseContext); |
1470 | 1470 | // Do a pass over the next row. |
1471 | 1471 | // Don't bubble properties in this case. |
1472 | 1472 | return next; |
@@ -1499,7 +1499,7 @@ function completeWork( |
1499 | 1499 | } |
1500 | 1500 | case OffscreenComponent: |
1501 | 1501 | case LegacyHiddenComponent: { |
1502 | | - popRenderLanes(workInProgress); |
| 1502 | + popHiddenContext(workInProgress); |
1503 | 1503 | const nextState: OffscreenState | null = workInProgress.memoizedState; |
1504 | 1504 | const nextIsHidden = nextState !== null; |
1505 | 1505 |
|
@@ -1520,7 +1520,7 @@ function completeWork( |
1520 | 1520 | } else { |
1521 | 1521 | // Don't bubble properties for hidden children unless we're rendering |
1522 | 1522 | // at offscreen priority. |
1523 | | - if (includesSomeLane(subtreeRenderLanes, (OffscreenLane: Lane))) { |
| 1523 | + if (includesSomeLane(renderLanes, (OffscreenLane: Lane))) { |
1524 | 1524 | bubbleProperties(workInProgress); |
1525 | 1525 | // Check if there was an insertion or update in the hidden subtree. |
1526 | 1526 | // If so, we need to hide those nodes in the commit phase, so |
|