-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] Update current value with a ref
Originally we updated it in the subscription handler so that we could be sure it always represented the latest snapshot. However, we run into problems because the `getSnapshot` could change the next time in the same batch as the re-render, in which case the value is no longer correct. So this moves it back to the commit phase. We avoid the stale `getSnapshot` problem with a tearing check in the commit phase whenever `getSnapshot` changes. Since `getSnapshot` is designed to be fast, I combined both into a single `useLayoutEffect`, along with the one we do when `subscribe` changes, to save some memory.
- Loading branch information
Showing
1 changed file
with
9 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters