fix(powersync): Don't flush records when diff trigger isn't setup yet when using `on-demand` mode. #1585
main fromrefs/pull/1585/head·merged by tannerlinsley 🎯 Changes#
Users reported an error that occurs during startup when using on-demand: An error has been detected in the sync handler Error: no such table: __XXXX_tracking_6bed0e00. During initialisation we were flushing records before the diff trigger was setup.
This change simply skips flushing if the diff trigger hasn't been setup yet.
✅ Checklist#
- I have tested this code locally with
pnpm test.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
Summary by CodeRabbit#
- Bug Fixes
- Reduced on-demand sync log spam by avoiding premature diff flushes before tracking is initialized.
- Prevented incorrect flush/disposal behavior during unload/disposal, avoiding attempts to flush tracking after it’s no longer valid.
- Improved first-time subset loading to skip flush/dispose when sync tracking isn’t configured yet.
- 1
@samwillis - could you review this one please?
Thanks for this. I pulled it into a stack with #1688 and ran the PowerSync package tests. The initial guard is pointed in the right direction, but
disposeTrackingstays truthy after the tracking table has been disposed, so unload/cleanup can still try to flush the deleted table and logno such tableunder PowerSync 2.Can you clear the tracking state as part of disposal and add a regression test that fails on the old code, including the unload/cleanup path? Once that and CI are green, this should be good to merge.
Thanks for this. I pulled it into a stack with #1688 and ran the PowerSync package tests. The initial guard is pointed in the right direction, but
disposeTrackingstays truthy after the tracking table has been disposed, so unload/cleanup can still try to flush the deleted table and logno such tableunder PowerSync 2.Can you clear the tracking state as part of disposal and add a regression test that fails on the old code, including the unload/cleanup path? Once that and CI are green, this should be good to merge.
Done, thanks for the feedback!
More templates
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@1585@tanstack/browser-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1585@tanstack/capacitor-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1585@tanstack/cloudflare-durable-objects-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1585@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@1585@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@1585@tanstack/db-sqlite-persistence-core
npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1585@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@1585@tanstack/electron-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1585@tanstack/expo-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1585@tanstack/node-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1585@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@1585@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1585@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@1585@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@1585@tanstack/react-native-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1585@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1585@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@1585@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@1585@tanstack/tauri-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1585@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1585@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@1585commit:
bba5ee7tannerlinsley merged thisef0dc8c
tannerlinsley closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
d851ef2b-4e4d-40d1-a13d-ad5fc5056353📥 Commits
Reviewing files that changed from the base of the PR and between e830ffe7a6e75544c414fb1978f7785499f82562 and c43a5fe8a096ae49af90f2198b271cbd7e08608f.
📒 Files selected for processing (1)
.changeset/five-turtles-yell.md🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
This PR updates on-demand sync cleanup and initialization to skip diff-trigger flushing and disposal when no tracking trigger exists, preventing operations against uninitialized or dropped tracking tables.
Changes#
Diff trigger initialization safety
.changeset/five-turtles-yell.md,packages/powersync-db-collection/src/powersync.tsno such tableand cleanup fixes.Estimated code review effort: 2 (Simple) | ~8 minutes
🚥 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.
❤️ Share