Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Scheduler] Fix: Suspending an expired update (#15326)
When an async update expires, React renders at the expiration time that corresponds to the current time, not at the original update's expiration time. That way, all the expired work in the tree is flushed in a single batch. This is implemented inside `renderRoot` by comparing the next render expiration time to the current time. If the current time is later, `renderRoot` will restart at the later time. Because of poor factoring, the check is currently performed right before entering the work loop. But the work loop is usually entered multiple times in a single callback: each time a component throws or suspends. This led to an infinite loop where React would detect that an update expired, restart at the current time, make a bit of progress, suspend, check for expired work again, and start the loop again. I fixed this by moving the expired work check to the beginning of `renderRoot`, so that it is not performed every time something suspends. This isn't ideal, because you could technically still fall into a loop if more than 10ms lapse in between exiting `renderRoot` and entering it again. The proper fix is to lift the check outside of `renderRoot` entirely so that the function can restart without checking for expired work again. Since this is exceedingly unlikely (and this whole thing is still behind a flag), I'll do the better fix in an already-planned follow up to fork `renderRoot` into separate functions for sync and async work.
- Loading branch information