Skip to content
Source
Sign inSign up
TanStack/db

fix(powersync): Don't flush records when diff trigger isn't setup yet when using `on-demand` mode. #1585

MergedChriztiaan(GitHub profile, opens in a new tab)merged 10 commits intomain fromrefs/pull/1585/headmerged 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. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      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)
      • .changeset/five-turtles-yell.md

      📝 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

      Layer / File(s)Summary
      Guard diff trigger initialization in load/unload paths
      .changeset/five-turtles-yell.md, packages/powersync-db-collection/src/powersync.ts
      On-demand sync now conditionally flushes and disposes tracking during first subscription setup and final predicate removal. The changeset documents the associated no such table and cleanup fixes.

      Estimated code review effort: 2 (Simple) | ~8 minutes

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the main on-demand flush fix in this PR.
      Description check✅ PassedThe description follows the template and includes changes, checklist, and release impact details.
      Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. @samwillis - could you review this one please?

    3. 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 disposeTracking stays truthy after the tracking table has been disposed, so unload/cleanup can still try to flush the deleted table and log no such table under 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.

    4. 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 disposeTracking stays truthy after the tracking table has been disposed, so unload/cleanup can still try to flush the deleted table and log no such table under 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!

    5. 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@1585

      commit: bba5ee7

    6. tannerlinsley merged thisef0dc8c

    7. tannerlinsley closed this

Sign in to join this conversation.