@@ -286,42 +286,34 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
286286 let nextLanes = NoLanes ;
287287 let nextLanePriority = NoLanePriority ;
288288
289- const expiredLanes = root . expiredLanes ;
290289 const suspendedLanes = root . suspendedLanes ;
291290 const pingedLanes = root . pingedLanes ;
292291
293- // Check if any work has expired.
294- if ( expiredLanes !== NoLanes ) {
295- // TODO: Should entangle with SyncLane
296- nextLanes = expiredLanes ;
297- nextLanePriority = return_highestLanePriority = SyncLanePriority ;
298- } else {
299- // Do not work on any idle work until all the non-idle work has finished,
300- // even if the work is suspended.
301- const nonIdlePendingLanes = pendingLanes & NonIdleLanes ;
302- if ( nonIdlePendingLanes !== NoLanes ) {
303- const nonIdleUnblockedLanes = nonIdlePendingLanes & ~ suspendedLanes ;
304- if ( nonIdleUnblockedLanes !== NoLanes ) {
305- nextLanes = getHighestPriorityLanes ( nonIdleUnblockedLanes ) ;
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 ) ;
306304 nextLanePriority = return_highestLanePriority ;
307- } else {
308- const nonIdlePingedLanes = nonIdlePendingLanes & pingedLanes ;
309- if ( nonIdlePingedLanes !== NoLanes ) {
310- nextLanes = getHighestPriorityLanes ( nonIdlePingedLanes ) ;
311- nextLanePriority = return_highestLanePriority ;
312- }
313305 }
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 ;
314313 } else {
315- // The only remaining work is Idle.
316- const unblockedLanes = pendingLanes & ~ suspendedLanes ;
317- if ( unblockedLanes !== NoLanes ) {
318- nextLanes = getHighestPriorityLanes ( unblockedLanes ) ;
314+ if ( pingedLanes !== NoLanes ) {
315+ nextLanes = getHighestPriorityLanes ( pingedLanes ) ;
319316 nextLanePriority = return_highestLanePriority ;
320- } else {
321- if ( pingedLanes !== NoLanes ) {
322- nextLanes = getHighestPriorityLanes ( pingedLanes ) ;
323- nextLanePriority = return_highestLanePriority ;
324- }
325317 }
326318 }
327319 }
@@ -463,6 +455,7 @@ export function markStarvedLanesAsExpired(
463455 // expiration time. If so, we'll assume the update is being starved and mark
464456 // it as expired to force it to finish.
465457 let lanes = pendingLanes ;
458+ let expiredLanes = 0 ;
466459 while ( lanes > 0 ) {
467460 const index = pickArbitraryLaneIndex ( lanes ) ;
468461 const lane = 1 << index ;
@@ -481,11 +474,15 @@ export function markStarvedLanesAsExpired(
481474 }
482475 } else if ( expirationTime <= currentTime ) {
483476 // This lane expired
484- root . expiredLanes |= lane ;
477+ expiredLanes |= lane ;
485478 }
486479
487480 lanes &= ~ lane ;
488481 }
482+
483+ if ( expiredLanes !== 0 ) {
484+ markRootExpired ( root , expiredLanes ) ;
485+ }
489486}
490487
491488// This returns the highest priority pending lanes regardless of whether they
@@ -668,7 +665,17 @@ export function markRootPinged(
668665}
669666
670667export function markRootExpired ( root : FiberRoot , expiredLanes : Lanes ) {
671- root . expiredLanes |= expiredLanes & root . pendingLanes ;
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 ;
672679}
673680
674681export function markRootMutableRead ( root : FiberRoot , updateLane : Lane ) {
@@ -684,7 +691,6 @@ export function markRootFinished(root: FiberRoot, remainingLanes: Lanes) {
684691 root . suspendedLanes = 0 ;
685692 root . pingedLanes = 0 ;
686693
687- root . expiredLanes &= remainingLanes ;
688694 root . mutableReadLanes &= remainingLanes ;
689695
690696 root . entangledLanes &= remainingLanes ;
0 commit comments