@@ -322,7 +322,7 @@ const SuspendedOnError: SuspendedReason = 1;
322
322
const SuspendedOnData : SuspendedReason = 2 ;
323
323
const SuspendedOnImmediate : SuspendedReason = 3 ;
324
324
const SuspendedOnDeprecatedThrowPromise : SuspendedReason = 4 ;
325
- const SuspendedAndReadyToUnwind : SuspendedReason = 5 ;
325
+ const SuspendedAndReadyToContinue : SuspendedReason = 5 ;
326
326
const SuspendedOnHydration : SuspendedReason = 6 ;
327
327
328
328
// When this is true, the work-in-progress fiber just suspended (or errored) and
@@ -892,6 +892,18 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
892
892
return ;
893
893
}
894
894
895
+ // If this root is currently suspended and waiting for data to resolve, don't
896
+ // schedule a task to render it. We'll either wait for a ping, or wait to
897
+ // receive an update.
898
+ if (
899
+ workInProgressSuspendedReason === SuspendedOnData &&
900
+ workInProgressRoot === root
901
+ ) {
902
+ root . callbackPriority = NoLane ;
903
+ root . callbackNode = null ;
904
+ return ;
905
+ }
906
+
895
907
// We use the highest priority lane to represent the priority of the callback.
896
908
const newCallbackPriority = getHighestPriorityLane ( nextLanes ) ;
897
909
@@ -1153,20 +1165,6 @@ function performConcurrentWorkOnRoot(
1153
1165
if ( root . callbackNode === originalCallbackNode ) {
1154
1166
// The task node scheduled for this root is the same one that's
1155
1167
// currently executed. Need to return a continuation.
1156
- if (
1157
- workInProgressSuspendedReason === SuspendedOnData &&
1158
- workInProgressRoot === root
1159
- ) {
1160
- // Special case: The work loop is currently suspended and waiting for
1161
- // data to resolve. Unschedule the current task.
1162
- //
1163
- // TODO: The factoring is a little weird. Arguably this should be checked
1164
- // in ensureRootIsScheduled instead. I went back and forth, not totally
1165
- // sure yet.
1166
- root . callbackPriority = NoLane ;
1167
- root . callbackNode = null ;
1168
- return null ;
1169
- }
1170
1168
return performConcurrentWorkOnRoot . bind ( null , root ) ;
1171
1169
}
1172
1170
return null ;
@@ -1858,7 +1856,7 @@ function handleThrow(root: FiberRoot, thrownValue: any): void {
1858
1856
case SuspendedOnData :
1859
1857
case SuspendedOnImmediate :
1860
1858
case SuspendedOnDeprecatedThrowPromise :
1861
- case SuspendedAndReadyToUnwind : {
1859
+ case SuspendedAndReadyToContinue : {
1862
1860
const wakeable : Wakeable = ( thrownValue : any ) ;
1863
1861
markComponentSuspended (
1864
1862
erroredWork ,
@@ -2216,6 +2214,17 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
2216
2214
// `status` field, but if the promise already has a status, we won't
2217
2215
// have added a listener until right here.
2218
2216
const onResolution = ( ) = > {
2217
+ // Check if the root is still suspended on this promise.
2218
+ if (
2219
+ workInProgressSuspendedReason === SuspendedOnData &&
2220
+ workInProgressRoot === root
2221
+ ) {
2222
+ // Mark the root as ready to continue rendering.
2223
+ workInProgressSuspendedReason = SuspendedAndReadyToContinue ;
2224
+ }
2225
+ // Ensure the root is scheduled. We should do this even if we're
2226
+ // currently working on a different root, so that we resume
2227
+ // rendering later.
2219
2228
ensureRootIsScheduled ( root , now ( ) ) ;
2220
2229
} ;
2221
2230
thenable . then ( onResolution , onResolution ) ;
@@ -2225,10 +2234,10 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
2225
2234
// If this fiber just suspended, it's possible the data is already
2226
2235
// cached. Yield to the main thread to give it a chance to ping. If
2227
2236
// it does, we can retry immediately without unwinding the stack.
2228
- workInProgressSuspendedReason = SuspendedAndReadyToUnwind ;
2237
+ workInProgressSuspendedReason = SuspendedAndReadyToContinue ;
2229
2238
break outer ;
2230
2239
}
2231
- case SuspendedAndReadyToUnwind : {
2240
+ case SuspendedAndReadyToContinue : {
2232
2241
const thenable : Thenable < mixed > = ( thrownValue : any ) ;
2233
2242
if ( isThenableResolved ( thenable ) ) {
2234
2243
// The data resolved. Try rendering the component again.
0 commit comments