Repository navigation
fix(sync): wait for persist load before an explicit sync() (#659) - #673
Open
LinusOssmann wants to merge 1 commit into
Open
LinusOssmann wants to merge 1 commit into
LinusOssmann wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #659.
Problem
loadLocal()is async and not awaited, butsyncState(obs$).syncis assigned synchronously. An explicitsync()that runs beforeisPersistLoadedreadslocalState.pendingChanges(stillundefined) andmetadata.lastSync(stillundefined), and consumes the one-shotisSyncedreplay with that empty snapshot. When the load finishes a moment later, the persisted pending changes are never applied, on this launch or any later one if the app syncs early again. The implicit activation path is already gated withwhen(onAllPersistLoaded); the explicit path is not.Fix
Wait for
isPersistLoadedat the top ofsync()when the observable is persisted. This is a no-op for the implicit path (already loaded) and for observables withoutpersist. Side effect: an early explicitsync()now uses the persistedlastSync(delta fetch) instead ofundefined(full fetch).Test
Adds a regression test in
tests/persist.test.tswith a persist plugin whoseloadTableresolves on demand. It fails onmain(createis never called) and passes with the fix. The rest of the suite is unchanged.