diff options
| author | Fuwn <[email protected]> | 2026-03-28 06:09:40 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-28 06:09:40 +0000 |
| commit | b48a27fe04d893c92b28c97d3f78357ce67bb419 (patch) | |
| tree | 89f568bfbd26b404bbb3e09fb29e3af50890be46 /src/stores/stateBin.ts | |
| parent | fix(preferences): preserve partial preference updates (diff) | |
| download | due.moe-b48a27fe04d893c92b28c97d3f78357ce67bb419.tar.xz due.moe-b48a27fe04d893c92b28c97d3f78357ce67bb419.zip | |
fix(cache): preserve hydrated client state
Diffstat (limited to 'src/stores/stateBin.ts')
| -rw-r--r-- | src/stores/stateBin.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts index 06d34bef..1d3f5dee 100644 --- a/src/stores/stateBin.ts +++ b/src/stores/stateBin.ts @@ -13,14 +13,22 @@ interface StateBin { const STORAGE_KEY = "stateBin"; const baseStore = writable<StateBin>({}); +let hydrated = !browser; +let state: StateBin = {}; if (browser) { localforage.getItem<StateBin>(STORAGE_KEY).then((value) => { if (value && typeof value === "object") baseStore.set(value); + + hydrated = true; + + localforage.setItem(STORAGE_KEY, state); }); baseStore.subscribe((value) => { - localforage.setItem(STORAGE_KEY, value); + state = value; + + if (hydrated) localforage.setItem(STORAGE_KEY, value); }); } |