diff --git a/app/store/sync.ts b/app/store/sync.ts index 8ee6c1819f4..d3582e3c935 100644 --- a/app/store/sync.ts +++ b/app/store/sync.ts @@ -97,11 +97,18 @@ export const useSyncStore = createPersistStore( const client = this.getClient(); try { - const remoteState = JSON.parse( - await client.get(config.username), - ) as AppState; - mergeAppState(localState, remoteState); - setLocalAppState(localState); + const remoteState = await client.get(config.username); + if (!remoteState || remoteState === "") { + await client.set(config.username, JSON.stringify(localState)); + console.log("[Sync] Remote state is empty, using local state instead."); + return + } else { + const parsedRemoteState = JSON.parse( + await client.get(config.username), + ) as AppState; + mergeAppState(localState, parsedRemoteState); + setLocalAppState(localState); + } } catch (e) { console.log("[Sync] failed to get remote state", e); throw e;