Skip to content

@stainless-code/persist

Hydration-aware persistence for any reactive store — zero-dep persistSource core; codecs, backends, cross-tab transport, source + framework hydration adapters ship as opt-in recipes

svelte-store-persist

58 linesSource

Gate Svelte store-based UI on Persist hydration with hydratedStore (Readable). Use for Svelte 3–4 or Svelte 5 apps that still use stores; runes UI → svelte-persist.

Svelte stores hydration gate

@stainless-code/persist/frameworks/svelte-store exports hydratedStore(signal) → Readable<boolean>. Use $hydrated auto-subscribe in templates. Separate public entry from ./frameworks/svelte (runes).

Install

shell
bun add @stainless-code/persist svelte

Peer: svelte >=3.0.0.

Minimal wiring

svelte
<script>
  import { hydratedStore } from "@stainless-code/persist/frameworks/svelte-store";
  const hydrated = hydratedStore(prefsHydration);
</script>

{#if !$hydrated}
  <Skeleton />
{:else}
  <Prefs />
{/if}

Contracts

Null/undefined → readable(true). SSR: hydrated true.

Common mistakes

  • Using this for Svelte 5 runes UI. Use svelte-persist / hydratedRune.
  • Forgetting the $ prefix in templates.
  • Null signal ≠ loading → readable(true).

API surface

  • hydratedStore(signal) → Readable<boolean>

See also: svelte-persist.