Skip to content

Commit

Permalink
fix: hydrated for indexedDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogtiti committed Sep 3, 2024
1 parent 7b6fe66 commit 886ffc0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/utils/indexedDB-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import { get, set, del, clear } from "idb-keyval";
class IndexedDBStorage implements StateStorage {
public async getItem(name: string): Promise<string | null> {
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);
}
}

public async setItem(name: string, value: string): Promise<void> {
try {
const _value = JSON.parse(value);
if (!_value?.state?._hasHydrated) {
return;
}
await set(name, value);
} catch (error) {
localStorage.setItem(name, value);
Expand Down

0 comments on commit 886ffc0

Please sign in to comment.