Invental/Review lessons/Client state that goes stale

Client state that goes stale

No global store writes during a server render

A client store that is a module singleton becomes shared state across users the moment it runs on a server; pass server-loaded data down per request (context or props), never by writing it into the global store during render.

01 · Before and afterThe pattern

TSX
// before: render-time write into a module-level store (shared by every SSR request)
useStore.getState().seed(id, loaderData);

// after: request-scoped value, store stays untouched on the server
const Initial = createContext<Bundle | null>(null);
<Initial.Provider value={loaderData ?? null}>{children}</Initial.Provider>;
// consumer: live store value wins, context is the fallback
const data = useStore((s) => s.bundles[id]) ?? use(Initial);

02 · Run it on your appThe check

Does any server-rendered page write into a global client store (Zustand, Redux, a module variable) while rendering?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.