aboutsummaryrefslogtreecommitdiff
path: root/src/stores/stateBin.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-28 06:09:40 +0000
committerFuwn <[email protected]>2026-03-28 06:09:40 +0000
commitb48a27fe04d893c92b28c97d3f78357ce67bb419 (patch)
tree89f568bfbd26b404bbb3e09fb29e3af50890be46 /src/stores/stateBin.ts
parentfix(preferences): preserve partial preference updates (diff)
downloaddue.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.ts10
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);
});
}