diff options
| author | Fuwn <[email protected]> | 2026-03-28 06:26:19 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-28 06:26:19 +0000 |
| commit | c1475d4adb535b374cbf4a4aababd95986cfbabb (patch) | |
| tree | f80d2ef2c839778529b31dd0d625efa18e52cfe9 /src/stores/stateBin.ts | |
| parent | fix(notifications): stabilize browser subscription identity (diff) | |
| download | due.moe-c1475d4adb535b374cbf4a4aababd95986cfbabb.tar.xz due.moe-c1475d4adb535b374cbf4a4aababd95986cfbabb.zip | |
fix(cache): keep pre-hydration state changes
Diffstat (limited to 'src/stores/stateBin.ts')
| -rw-r--r-- | src/stores/stateBin.ts | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/stores/stateBin.ts b/src/stores/stateBin.ts index 1d3f5dee..ca61ed77 100644 --- a/src/stores/stateBin.ts +++ b/src/stores/stateBin.ts @@ -15,10 +15,17 @@ const STORAGE_KEY = "stateBin"; const baseStore = writable<StateBin>({}); let hydrated = !browser; let state: StateBin = {}; +let changedBeforeHydration = false; +let initialEmission = true; +let applyingStoredValue = false; if (browser) { localforage.getItem<StateBin>(STORAGE_KEY).then((value) => { - if (value && typeof value === "object") baseStore.set(value); + if (value && typeof value === "object" && !changedBeforeHydration) { + applyingStoredValue = true; + baseStore.set(value); + applyingStoredValue = false; + } hydrated = true; @@ -28,7 +35,12 @@ if (browser) { baseStore.subscribe((value) => { state = value; + if (browser && !hydrated && !initialEmission && !applyingStoredValue) + changedBeforeHydration = true; + if (hydrated) localforage.setItem(STORAGE_KEY, value); + + initialEmission = false; }); } |