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 6 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 6 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
    • Fixed a non-critical error being logged during startup in on-demand sync mode.
    • Improved initialization to prevent unnecessary operations when sync tracking is not yet configured.

@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

Run ID: 068a86bc-4943-433b-82f5-708d493861ca

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1abde and e830ffe.

📒 Files selected for processing (2)
  • .changeset/five-turtles-yell.md
  • packages/powersync-db-collection/src/powersync.ts

📝 Walkthrough

Walkthrough

This PR adds defensive null checks to prevent flushing and disposing a diff trigger that hasn't been created yet during on-demand sync initialization, eliminating non-critical errors logged at startup in the loadSubset path.

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
Changeset documents that startup now skips flushing when diffTrigger is unconfigured. Code guards check disposeTracking before flushing/disposing in both the unload path (when last predicate is removed) and load path (on first subscription).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • samwillis

Poem

🐰 A trigger that's not yet begun,
Now knows not to flush in the sun,
Guards catch the case,
At startup's own pace,
Errors begone—initialization is won!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing record flushing during initialization when the diff trigger isn't configured in on-demand mode.
Description check ✅ Passed The description follows the template structure with clear sections explaining the issue, solution, and confirms testing and changeset generation.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

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.

2 participants