fix(db-sqlite-persistence-core): persisted preload() hangs when upstream sync never calls markReady#1615
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)
📝 WalkthroughWalkthroughPersisted SQLite sync startup now marks collections ready even when upstream sync never calls ChangesPersisted preload readiness
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/db-sqlite-persistence-core/src/persisted.ts`:
- Around line 2563-2570: The loopback startup flow in ensureStarted() still
calls params.markReady() unconditionally in the finally block, which can race
with cleanup() and re-mark a cleaned-up collection ready. Update the persisted
loopback path to mirror the guarded wrapped path by checking
startupState.cleanedUp before calling params.markReady(). Keep the fix localized
around the runtime.ensureStarted().catch(...).finally(...) chain in persisted.ts
so the lifecycle transition stays valid even when startup finishes late.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b90cf813-03a8-4896-9265-35c0a866016b
📒 Files selected for processing (3)
.changeset/free-rivers-like.mdpackages/db-sqlite-persistence-core/src/persisted.tspackages/db-sqlite-persistence-core/tests/persisted.test.ts
🎯 Changes
collection.preload()andtoArrayWhenReady()hung forever when the upstream sync never calledmarkReady(). This happens in when TanStack Query'snetworkMode: 'offlineFirst'pauses a query because the device is offline, paused queries never reachisSuccessorisError, somarkReady()is never called, and consumers block indefinitely even though SQLite has local data available.Fix
After
ensureStarted()resolves (SQLite hydration complete),params.markReady()is now called directly increateWrappedSyncConfig, independent of the upstream sync. This is skipped in on-demand mode because no rows load at startup there, the upstream sync owns readiness in that case. If the upstream sync also callsmarkReady(), the second call is safely ignored by the lifecycle layer.✅ Checklist
pnpm test.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
preload()could hang when upstream synchronization never signals readiness.Tests
preload()completing even when synchronization never calls readiness signaling, and verifying the data is available afterward.