fix(electric-db-collection): preserve persisted rows on progressive resume#1493
Open
pkudinov wants to merge 1 commit intoTanStack:mainfrom
Open
fix(electric-db-collection): preserve persisted rows on progressive resume#1493pkudinov wants to merge 1 commit intoTanStack:mainfrom
pkudinov wants to merge 1 commit intoTanStack:mainfrom
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.
Summary
Fixes #1478.
Progressive Electric collections wrapped with SQLite persistence can hydrate rows from the persisted store, then wipe them when the resumed Electric stream sends an
up-to-datecontrol message without replaying snapshot rows.This changes progressive startup so a valid persisted Electric resume point is treated as already past the initial atomic-swap phase. That preserves hydrated persisted rows while still allowing normal progressive initial sync to use the existing buffer/truncate/apply behavior.
Root cause
Progressive mode uses the first
up-to-datemessage to finish initial sync by truncating the collection and replaying buffered stream rows. With persisted resume metadata, the stream starts from a savedhandle/offset, so it may legitimately sendup-to-datewith no old rows. The collection had already hydrated those rows from persistence, but the initial atomic swap ran anyway and truncated them.Changes
hasReceivedUpToDatewhen using a compatible persisted Electric resume point.up-to-datewithout snapshot rows, and verifies rows remain in memory and persistence.@tanstack/electric-db-collection.Validation
I also verified this patch in a real Next.js app using browser OPFS SQLite persistence: after resetting local SQLite, loading a persisted progressive Electric collection, and refreshing/warm-loading twice, the collection stayed populated instead of dropping to zero rows.