Rxova
Skip to content

indexedDbAdapter

function indexedDbAdapter(key, options?): PersistAdapter;

Persist to IndexedDB.

Two things this has that localStorage does not.

Real fidelity, with no serializer. IndexedDB stores values with the structured clone algorithm — the same one BroadcastChannel uses — so a Date comes back a Date and a Map a Map, for free. The whole JSON-degrades-your-types problem the Serializer seam exists to solve simply is not present here, and passing a serializer would only reintroduce it. That makes this the right home for state that is not JSON-shaped.

Room. localStorage is a few megabytes per origin and shared with everything else on it; IndexedDB is orders of magnitude larger.

And one thing it does not have.

A synchronous flush. read is asynchronous, so the store is handed back before its state arrives — which is exactly the window store.hydrated and useHydrated exist to close. Gate first input on one of them, or a keystroke landing in that window is discarded by last-writer-wins when the restore lands holding an older but higher-counter value.

The same asymmetry applies on the way out: a pagehide flush cannot be awaited, so the last debounced write before a tab closes may not land. The debounce (persist.debounceMs, default 100) is the real protection — keep it short for state you would mind losing, or keep that state in localStorageAdapter, which writes synchronously, and the bulk here.

ParameterType
keystring
optionsIndexedDbAdapterOptions

PersistAdapter