React / Editorial solution guide
Diagnose external store snapshots and hydration
Trace unstable snapshots, leaked subscriptions, and server-to-client initial data disagreements.
Read-only knowledge base · No public comments
Recognize the symptoms
A consumer repeatedly renders, a cached-snapshot warning appears, or a server-rendered value changes unexpectedly during hydration. Listeners may also remain active after a component is removed.
Record the exact warning, store implementation, rendering environment and smallest reproducible interaction. Avoid reproducing a runaway update loop in a shared environment.
Understand the likely causes
- A snapshot function returns a new object on every read even though the underlying data is unchanged, or a subscribe function fails to return cleanup for its original listener.
- The server and initial hydration snapshots may differ. A shared server module may also accidentally reuse private data between requests; that isolation problem requires separate investigation.
1. Classify the failing boundary
Identify whether the problem occurs on repeated snapshot reads, during a store update, after unmount, or only on a direct server-rendered load. Capture a minimal store with synthetic values and one consumer. For a hydration warning, compare the initial server output and client snapshot before investigating later updates. Keep request-specific values out of logs and avoid treating a warning alone as evidence of a data leak.
2. Compare snapshot identity and updates
Read the snapshot twice without changing the store and compare identity. If immutable data is returned as a new object each time, cache the result until its relevant inputs change. Then perform one update and verify the changed snapshot is published before listeners are notified. A stable snapshot must still change when its observed data changes; mutating an existing object in place can conceal the update.
3. Check listener ownership and hydration
Record registration and cleanup for the same callback. Mount and unmount a single consumer, then update the store and confirm the removed callback is no longer notified. Keep subscribe stable where practical to avoid unnecessary resubscriptions. For server rendering, provide matching initial server and hydration snapshots; transfer initial data only to its authorized client and scope private server stores to the request.
4. Verify the repair
Repeat the original bounded reproduction and confirm the warning no longer occurs. Check unchanged reads, a genuine update, cleanup, remount and a direct server-rendered load. Use two synthetic request contexts to verify that one cannot observe the other’s private data. Retain these cases as regression tests and monitor only appropriately redacted diagnostics; successful hydration does not by itself prove authorization or broader data isolation.
Verify the fix
The original interaction completes without repeated snapshot warnings, subscribers observe real changes, and cleanup removes the correct listener. Server and first hydration snapshots match for each controlled request.
Keep it from recurring
- Document snapshot identity, update ordering, subscription cleanup and request ownership alongside the store API. Include both unchanged reads and actual updates in tests, as well as direct server-rendered navigation when supported.