Skip to content

Commit

Permalink
Restart websocket flow if persistedSyncState isnt loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Mar 20, 2024
1 parent 33fdadd commit 1c4328e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addons/dexie-cloud/src/sync/connectWebSocket.ts
Expand Up @@ -96,10 +96,14 @@ export function connectWebSocket(db: DexieCloudDB) {
),
distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash ),
switchMap(([userLogin, realmSetHash]) => {
if (!db.cloud.persistedSyncState?.value) {
// Restart the flow if persistedSyncState is not yet available.
return createObservable();
}
// Let server end query changes from last entry of same client-ID and forward.
// If no new entries, server won't bother the client. If new entries, server sends only those
// and the baseRev of the last from same client-ID.
if (userLogin && db.cloud.persistedSyncState?.value) {
if (userLogin) {
return new WSObservable(
db.cloud.options!.databaseUrl,
db.cloud.persistedSyncState!.value!.serverRevision,
Expand Down

0 comments on commit 1c4328e

Please sign in to comment.