( root: FiberRoot, currentTime: number, )
| 535 | } |
| 536 | |
| 537 | export function markStarvedLanesAsExpired( |
| 538 | root: FiberRoot, |
| 539 | currentTime: number, |
| 540 | ): void { |
| 541 | // TODO: This gets called every time we yield. We can optimize by storing |
| 542 | // the earliest expiration time on the root. Then use that to quickly bail out |
| 543 | // of this function. |
| 544 | |
| 545 | const pendingLanes = root.pendingLanes; |
| 546 | const suspendedLanes = root.suspendedLanes; |
| 547 | const pingedLanes = root.pingedLanes; |
| 548 | const expirationTimes = root.expirationTimes; |
| 549 | |
| 550 | // Iterate through the pending lanes and check if we've reached their |
| 551 | // expiration time. If so, we'll assume the update is being starved and mark |
| 552 | // it as expired to force it to finish. |
| 553 | // TODO: We should be able to replace this with upgradePendingLanesToSync |
| 554 | // |
| 555 | // We exclude retry lanes because those must always be time sliced, in order |
| 556 | // to unwrap uncached promises. |
| 557 | // TODO: Write a test for this |
| 558 | let lanes = enableRetryLaneExpiration |
| 559 | ? pendingLanes |
| 560 | : pendingLanes & ~RetryLanes; |
| 561 | while (lanes > 0) { |
| 562 | const index = pickArbitraryLaneIndex(lanes); |
| 563 | const lane = 1 << index; |
| 564 | |
| 565 | const expirationTime = expirationTimes[index]; |
| 566 | if (expirationTime === NoTimestamp) { |
| 567 | // Found a pending lane with no expiration time. If it's not suspended, or |
| 568 | // if it's pinged, assume it's CPU-bound. Compute a new expiration time |
| 569 | // using the current time. |
| 570 | if ( |
| 571 | (lane & suspendedLanes) === NoLanes || |
| 572 | (lane & pingedLanes) !== NoLanes |
| 573 | ) { |
| 574 | // Assumes timestamps are monotonically increasing. |
| 575 | expirationTimes[index] = computeExpirationTime(lane, currentTime); |
| 576 | } |
| 577 | } else if (expirationTime <= currentTime) { |
| 578 | // This lane expired |
| 579 | root.expiredLanes |= lane; |
| 580 | } |
| 581 | |
| 582 | lanes &= ~lane; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | // This returns the highest priority pending lanes regardless of whether they |
| 587 | // are suspended. |
no test coverage detected