@@ -286,38 +286,44 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
286286 let nextLanes = NoLanes ;
287287 let nextLanePriority = NoLanePriority ;
288288
289+ const expiredLanes = root . expiredLanes ;
289290 const suspendedLanes = root . suspendedLanes ;
290291 const pingedLanes = root . pingedLanes ;
291292
292- // Do not work on any idle work until all the non-idle work has finished,
293- // even if the work is suspended.
294- const nonIdlePendingLanes = pendingLanes & NonIdleLanes ;
295- if ( nonIdlePendingLanes !== NoLanes ) {
296- const nonIdleUnblockedLanes = nonIdlePendingLanes & ~ suspendedLanes ;
297- if ( nonIdleUnblockedLanes !== NoLanes ) {
298- nextLanes = getHighestPriorityLanes ( nonIdleUnblockedLanes ) ;
299- nextLanePriority = return_highestLanePriority ;
300- } else {
301- const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes ;
302- if ( nonIdlePingedLanes !== NoLanes ) {
303- nextLanes = getHighestPriorityLanes ( nonIdlePingedLanes ) ;
293+ // Check if any work has expired.
294+ if ( expiredLanes !== NoLanes ) {
295+ nextLanes = expiredLanes | SyncLane ;
296+ nextLanePriority = return_highestLanePriority = SyncLanePriority ;
297+ } else {
298+ // Do not work on any idle work until all the non-idle work has finished,
299+ // even if the work is suspended.
300+ const nonIdlePendingLanes = pendingLanes & NonIdleLanes ;
301+ if ( nonIdlePendingLanes !== NoLanes ) {
302+ const nonIdleUnblockedLanes = nonIdlePendingLanes & ~ suspendedLanes ;
303+ if ( nonIdleUnblockedLanes !== NoLanes ) {
304+ nextLanes = getHighestPriorityLanes ( nonIdleUnblockedLanes ) ;
304305 nextLanePriority = return_highestLanePriority ;
306+ } else {
307+ const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes ;
308+ if ( nonIdlePingedLanes !== NoLanes ) {
309+ nextLanes = getHighestPriorityLanes ( nonIdlePingedLanes ) ;
310+ nextLanePriority = return_highestLanePriority ;
311+ }
305312 }
306- }
307- } else {
308- // The only remaining work is Idle.
309- const unblockedLanes = pendingLanes & ~ suspendedLanes ;
310- if ( unblockedLanes !== NoLanes ) {
311- nextLanes = getHighestPriorityLanes ( unblockedLanes ) ;
312- nextLanePriority = return_highestLanePriority ;
313313 } else {
314- if ( pingedLanes !== NoLanes ) {
315- nextLanes = getHighestPriorityLanes ( pingedLanes ) ;
314+ // The only remaining work is Idle.
315+ const unblockedLanes = pendingLanes & ~ suspendedLanes ;
316+ if ( unblockedLanes !== NoLanes ) {
317+ nextLanes = getHighestPriorityLanes ( unblockedLanes ) ;
316318 nextLanePriority = return_highestLanePriority ;
319+ } else {
320+ if ( pingedLanes !== NoLanes ) {
321+ nextLanes = getHighestPriorityLanes ( pingedLanes ) ;
322+ nextLanePriority = return_highestLanePriority ;
323+ }
317324 }
318325 }
319326 }
320-
321327 if ( nextLanes === NoLanes ) {
322328 // This should only be reachable if we're suspended
323329 // TODO: Consider warning in this path if a fallback timer is not scheduled.
@@ -455,7 +461,6 @@ export function markStarvedLanesAsExpired(
455461 // expiration time. If so, we'll assume the update is being starved and mark
456462 // it as expired to force it to finish.
457463 let lanes = pendingLanes ;
458- let expiredLanes = 0 ;
459464 while ( lanes > 0 ) {
460465 const index = pickArbitraryLaneIndex ( lanes ) ;
461466 const lane = 1 << index ;
@@ -474,15 +479,11 @@ export function markStarvedLanesAsExpired(
474479 }
475480 } else if ( expirationTime <= currentTime ) {
476481 // This lane expired
477- expiredLanes |= lane ;
482+ root . expiredLanes |= lane ;
478483 }
479484
480485 lanes &= ~ lane ;
481486 }
482-
483- if ( expiredLanes !== 0 ) {
484- markRootExpired ( root , expiredLanes ) ;
485- }
486487}
487488
488489// This returns the highest priority pending lanes regardless of whether they
@@ -665,17 +666,7 @@ export function markRootPinged(
665666}
666667
667668export function markRootExpired ( root : FiberRoot , expiredLanes : Lanes ) {
668- const entanglements = root . entanglements ;
669- const SyncLaneIndex = 0 ;
670- entanglements [ SyncLaneIndex ] |= expiredLanes ;
671- root . entangledLanes |= SyncLane ;
672- root . pendingLanes |= SyncLane ;
673- }
674-
675- export function areLanesExpired ( root : FiberRoot , lanes : Lanes ) {
676- const SyncLaneIndex = 0 ;
677- const entanglements = root . entanglements ;
678- return ( entanglements [ SyncLaneIndex ] & lanes ) !== NoLanes ;
669+ root . expiredLanes |= expiredLanes & root . pendingLanes ;
679670}
680671
681672export function markRootMutableRead ( root : FiberRoot , updateLane : Lane ) {
@@ -691,6 +682,7 @@ export function markRootFinished(root: FiberRoot, remainingLanes: Lanes) {
691682 root . suspendedLanes = 0 ;
692683 root . pingedLanes = 0 ;
693684
685+ root . expiredLanes &= remainingLanes ;
694686 root . mutableReadLanes &= remainingLanes ;
695687
696688 root . entangledLanes &= remainingLanes ;
0 commit comments