From 886ffc0af89b2bf09c8a1af16648b00a629b584e Mon Sep 17 00:00:00 2001 From: Dogtiti <499960698@qq.com> Date: Tue, 3 Sep 2024 17:12:48 +0800 Subject: [PATCH] fix: hydrated for indexedDB --- app/utils/indexedDB-storage.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/utils/indexedDB-storage.ts b/app/utils/indexedDB-storage.ts index 51ee92b8185..b80c84ce932 100644 --- a/app/utils/indexedDB-storage.ts +++ b/app/utils/indexedDB-storage.ts @@ -4,7 +4,12 @@ import { get, set, del, clear } from "idb-keyval"; class IndexedDBStorage implements StateStorage { public async getItem(name: string): Promise { try { - return (await get(name)) || localStorage.getItem(name); + const value = (await get(name)) || localStorage.getItem(name); + const _value = JSON.parse(value); + if (_value?.state) { + _value.state._hasHydrated = true; + } + return JSON.stringify(_value); } catch (error) { return localStorage.getItem(name); } @@ -12,6 +17,10 @@ class IndexedDBStorage implements StateStorage { public async setItem(name: string, value: string): Promise { try { + const _value = JSON.parse(value); + if (!_value?.state?._hasHydrated) { + return; + } await set(name, value); } catch (error) { localStorage.setItem(name, value);