Describe the bug#
When using electricCollectionOptions with syncMode: "progressive" and persistedCollectionOptions (browser SQLite persistence), data hydrated from persistence gets wiped when the Electric stream reconnects after going offline. The collection drops to 0 items and never recovers.
Persistence and hydration work correctly on their own. The data loads from SQLite after a refresh while offline. The wipe happens the moment the stream comes back online.
To Reproduce#
- Create a persisted Electric collection with
syncMode: "progressive".
- Load the page. Data syncs and is persisted to SQLite.
- Go offline.
- Refresh the page. Data hydrates from SQLite. All rows are visible.
- Come back online.
- The collection is wiped to 0 items.
Expected behavior#
The collection should keep the hydrated rows and resume syncing changes from the stored offset. The stream does resume correctly (the offset and handle are sent in the reconnection request), but the in-memory state is wiped before the stream has a chance to deliver any data.
Desktop#
- OS: macOS
- Browser: Chromium (Electron)
Additional context#
@tanstack/db: 0.6.4
@tanstack/electric-db-collection: 0.3.2
@tanstack/react-db: 0.1.82
@tanstack/browser-db-sqlite-persistence: 0.1.8
@electric-sql/client: 1.5.15
We have observed the same problem and I took liberty to propose a fix which seems to be working for our case. Wonder if you check if it works for yours @danteissaias