useSyncExternalStore: Why Snapshot Identity and SSR Initial Values Matter
An external store can notify subscribers without changing what useSyncExternalStore renders, because the hook needs a snapshot that differs by Object.is. In this experiment, mutating the same snapshot object and notifying listeners left the screen showing 0, while replacing it with a new object updated the display to 2. Checking only whether a notification was sent therefore misses the difference. The test also covered hydration, where the client's initial read must receive the server's value, passed through window.__BOOTSTRAP__, even though the client store started with a newer value. The author notes that the experiment did not test rerenders from unrelated updates, the update loop caused by returning new objects on every read, or subscription performance at scale.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in