Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Sep 4, 2024
1 parent ed9aae5 commit 53dcae9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions app/store/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ export const usePromptStore = createPersistStore(
res.en.length + res.cn.length + res.tw.length;
SearchService.init(allPromptsForSearch, userPrompts);
});

return () => state.setHasHydrated(true);
},
},
);
1 change: 1 addition & 0 deletions app/utils/indexedDB-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class IndexedDBStorage implements StateStorage {
try {
const _value = JSON.parse(value);
if (!_value?.state?._hasHydrated) {
console.warn("skip setItem", name);
return;
}
await set(name, value);
Expand Down
11 changes: 6 additions & 5 deletions app/utils/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export function createPersistStore<T extends object, M>(
persistOptions: SecondParam<typeof persist<T & M & MakeUpdater<T>>>,
) {
persistOptions.storage = createJSONStorage(() => indexedDBStorage);
persistOptions.onRehydrateStorage = persistOptions.onRehydrateStorage
? persistOptions.onRehydrateStorage
: (state) => {
return () => state.setHasHydrated(true);
};
const oldOonRehydrateStorage = persistOptions?.onRehydrateStorage;
persistOptions.onRehydrateStorage = (state) => {
oldOonRehydrateStorage?.(state);
return () => state.setHasHydrated(true);
};

return create(
persist(
combine(
Expand Down

0 comments on commit 53dcae9

Please sign in to comment.