Skip to content

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

Open
Chriztiaan wants to merge 9 commits into
TanStack:mainfrom
powersync-ja:fix/no-flush-on-init
Open

fix(powersync): Don't flush records when diff trigger isn't setup yet when using on-demand mode.#1585
Chriztiaan wants to merge 9 commits into
TanStack:mainfrom
powersync-ja:fix/no-flush-on-init

Conversation

@Chriztiaan

@Chriztiaan Chriztiaan commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🎯 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.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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 e830ffe and c43a5fe.

📒 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 name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main on-demand flush fix in this PR.
Description check ✅ Passed The description follows the template and includes changes, checklist, and release impact details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check 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.

@Chriztiaan

Copy link
Copy Markdown
Contributor Author

@samwillis - could you review this one please?

@tannerlinsley

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants