wait for store hydration

This commit is contained in:
Wang Guan 2024-10-22 23:37:57 +09:00
parent 7869f7cc5f
commit 02ce9681ff

View File

@ -154,10 +154,18 @@ export function WindowContent(props: { children: React.ReactNode }) {
function useSyncOnStart() { function useSyncOnStart() {
const syncStore = useSyncStore(); const syncStore = useSyncStore();
const storeHasHydrated = useSyncStore((s) => s._hasHydrated);
useEffect(() => { useEffect(() => {
let running = true; let running = true;
setTimeout(async () => { setTimeout(async () => {
if (!(running && syncStore.cloudSync() && syncStore.autoSync.onStart)) { if (
!(
storeHasHydrated &&
running &&
syncStore.cloudSync() &&
syncStore.autoSync.onStart
)
) {
return; return;
} }
const dismissSyncingToast = showToast(Locale.Settings.Sync.IsSyncing); const dismissSyncingToast = showToast(Locale.Settings.Sync.IsSyncing);
@ -175,7 +183,7 @@ function useSyncOnStart() {
running = false; running = false;
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, [storeHasHydrated]);
} }
function Screen() { function Screen() {