-
Notifications
You must be signed in to change notification settings - Fork 130
fix(electric-db-colleciton): ignore snapshot-end before up-to-date
#924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(electric-db-colleciton): ignore snapshot-end before up-to-date
#924
Conversation
🦋 Changeset detectedLatest commit: 1e178db The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 87 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
8b977c5 to
10e4db1
Compare
snapshot-end before up-to-datesnapshot-end before up-to-date
kevin-dp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
|
🎉 This PR has been released! Thank you for your contribution! |
🎯 Changes
CI run failing with the reproduction from before fixing: https://github.com/TanStack/db/actions/runs/19739188291/job/56558506582?pr=924
Issue
In eager sync mode, a
snapshot-endmessage arriving before the firstup-to-datemessage was incorrectly triggering a commit, making data visible prematurely.Root Cause
Electric adds a
snapshot-endmarker after the initial snapshot data in the log. However, thissnapshot-endcan be from a significant period before the stream is actually up to date (i.e., fully synced with the current state of the database). The existing code at line 993 inelectric.ts:...would enter the commit logic for either message type. In the
elsebranch, transactions were committed wheneversnapshot-endarrived, even before the firstup-to-date:This caused eager mode to show potentially stale/incomplete data to users before the stream was truly up to date.
Note:
progressivemode was already protected because it buffers messages duringisBufferingInitialSync()and only commits onup-to-date.on-demandmode is not affected because the log is inchanges_onlymode and doesn't have an initial snapshot.Fix
Modified the commit logic to only commit on
snapshot-endif:up-to-datemessage, ORon-demandmode (wheresnapshot-endsemantically means "ready"), ORup-to-datehas already been received (hasReceivedUpToDateis true)This ensures that in eager mode,
snapshot-endbefore the firstup-to-dateis ignored (no commit), while subsequentsnapshot-endmessages (after the firstup-to-date) will correctly trigger commits.Tests
should ignore snapshot-end before first up-to-date in progressive modeshould commit on snapshot-end in eager mode AFTER first up-to-dateshould NOT commit multiple snapshot-end messages before up-to-date in eager mode✅ Checklist
pnpm test:pr.🚀 Release Impact