hydrate()
Reads every registered store's IndexedDB cache in parallel and dispatches whatever it finds — before any network request fires. This is what makes a repeat visit render instantly instead of showing a loading spinner.
- flux created via createFlux() — see api/create-flux
- Stores already registered via register() — see api/register
Basic usage
flux.hydrate() reads IDB for every registered store and dispatches whatever's cached. In a Next.js or React app, FluxProvider calls this once on mount — you rarely need to call it yourself.What happens per store
cachedAt and ttl.An expired cache entry is still dispatched immediately — the UI never waits on a network round trip just because the TTL passed. onStale is your hook for kicking off a refetch or showing a subtle "updating..." indicator alongside the stale data.
Parallel reads, isolated failures
Promise.allSettled, not a sequential loop. If one store's IDB read throws — a corrupted envelope, a quota issue — every other store still hydrates normally.The 2000ms hard timeout
HydrationGate waits for both flux.hydrated and the service worker's ready signal, but never longer than 2000ms — on a first visit with no SW installed yet, the app renders unhydrated rather than hanging.Scope-aware hydration
currentUserId to build the correct namespaced key for 'user'-scoped stores.A 'user'-scoped store hydrating before login isn't a failure case — it's treated as a cold cache. Loading clears and the store simply waits for the user-scope bootstrap() call once auth resolves. See core-concepts/multi-tenant-scoping.
LRU stores are skipped
ingestionType: 'LRU' registrations are never collectively hydrated at boot. The root idbKey only ever holds a heartbeat envelope used by the revalidation loop — never real data — so hydration explicitly skips it rather than dispatching that heartbeat as if it were the collection.idbGet on mount instead. Full behavior is covered in ingestion/lru.Reading hydration state
flux.isHydrated is a read-only boolean on the engine. useFlux() mirrors it as hydrated for components that need to react without wiring their own gate.For populating stores that had no cached data at all, see api/bootstrap. For the isolation model behind scope-aware hydration, see core-concepts/multi-tenant-scoping.