bootstrap()
Replaces every individual store's fetch call with one network request per scope. Leader election, TTL-aware revalidation, dynamic route chunk warming, and clock skew correction all attach to this one call — everything downstream just reads what it dispatches.
- flux created via createFlux() — see api/create-flux
- Stores already registered via register() for every key in your map
Basic usage
flux.bootstrap() once for public data on mount, and again with scope: 'user' once auth resolves. The two calls run under separate leader locks and cooldown timers, so one never blocks or resets the other.map can carry every channel you've registered for that scope. Whichever tab wins the leader lock fetches all of it in a single network request and dispatches each key to its matching store.
Config reference
endpoint and map are required. scope defaults to 'global'.scope and userId
'user'-scope call requires userId — Flux throws otherwise rather than silently writing to the wrong namespace. It's also what drives the boot-time stale-namespace sweep: if the incoming userId differs from the last one recorded on this browser, the previous user's entire IDB cache is evicted first.This sweep is what catches a session that never called clearUserSession() at all — a crashed tab, a closed laptop lid, a silently expired cookie. See core-concepts/multi-tenant-scoping.
authResolved — the anonymous sweep gate
'global'-scope call. It tells Flux you've definitively confirmed there's no active session right now — not merely that the user bootstrap hasn't run yet. Without this gate, the normal "public bootstrap on mount, user bootstrap once auth resolves" ordering would look identical to a logout and wipe a still-valid session's cache on every page load.Leader election and cooldown
flux:bootstrap:lead:global, flux:bootstrap:lead:user) and its own 30-second cooldown. One tab wins, fetches, and writes to IDB; every other open tab hydrates from disk instead of firing a second request.Response shape and asset warming
data keys are matched against map and dispatched to each registered store. assets — dynamic route chunk paths extracted server-side from your build manifest — get posted to the service worker as FLUX_WARM_CHUNKS so those routes work offline after this one call.Revalidation on focus and visibility
If a realtime adapter is connected, this revalidation loop won't fire a redundant HTTP refetch while a delta stream is actively catching a stale channel up — see core-concepts/activity-bus.
Clock skew correction
clockSkewMs from the response's Date header, correcting for latency. It's used internally for handshake replay timestamps, and exposed directly for anything your UI needs to display accurately.Error handling
online event retries immediately. Any other failure just serves whatever's already in IDB — bootstrap never rolls back a store to empty.For what happens to a 'user'-scoped bootstrap on logout, see api/clear-user-session. For the isolation model behind scope, see core-concepts/multi-tenant-scoping. For registering the stores this call dispatches into, see api/register.