fix(electric-db-collection): preserve persisted rows on progressive resume#1493
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughProgressive resume state now reuses valid persisted resumes without initial atomic-swap buffering. The test adapter supports seeded persisted rows and committed mutations, and an integration test verifies hydrated rows survive resume and subsequent updates. ChangesProgressive Persisted Resume
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant PersistedAdapter
participant ElectricCollection
participant ShapeStream
PersistedAdapter->>ElectricCollection: hydrate persisted rows and resume metadata
ElectricCollection->>ShapeStream: resume with persisted offset and handle
ShapeStream->>ElectricCollection: resumed insert and up-to-date message
ElectricCollection->>PersistedAdapter: persist final row state
Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
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.
Summary by CodeRabbit
Bug Fixes
Tests
Chores