Skip to content

Conversation

@ibarakaiev
Copy link
Contributor

When using join queries with collections configured with syncMode: 'on-demand', the source collections were never having their sync initialized. This caused join queries to return empty results because:

  1. On-demand collections use offset: 'now' and only receive changes from when sync starts, not historical data
  2. The lazy join loader calls requestSnapshot() to fetch matching rows
  3. Without startSyncImmediate(), the collection stays idle and requestSnapshot() has nothing to work with

The fix adds a collection.startSyncImmediate() call in subscribeToAllCollections() before subscribing, ensuring all source collections in a query (including those used in joins) have their sync properly initialized.

🤖 Generated with Claude Code

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

ibarakaiev and others added 2 commits December 29, 2025 11:04
When using join queries with collections configured with `syncMode: 'on-demand'`,
the source collections were never having their sync initialized. This caused
join queries to return empty results because:

1. On-demand collections use `offset: 'now'` and only receive changes from
   when sync starts, not historical data
2. The lazy join loader calls `requestSnapshot()` to fetch matching rows
3. Without `startSyncImmediate()`, the collection stays idle and
   `requestSnapshot()` has nothing to work with

The fix adds a `collection.startSyncImmediate()` call in
`subscribeToAllCollections()` before subscribing, ensuring all source
collections in a query (including those used in joins) have their sync
properly initialized.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2025

🦋 Changeset detected

Latest commit: c287949

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/db Patch
@tanstack/angular-db Patch
@tanstack/electric-db-collection Patch
@tanstack/offline-transactions Patch
@tanstack/powersync-db-collection Patch
@tanstack/query-db-collection Patch
@tanstack/react-db Patch
@tanstack/rxdb-db-collection Patch
@tanstack/solid-db Patch
@tanstack/svelte-db Patch
@tanstack/trailbase-db-collection Patch
@tanstack/vue-db Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ibarakaiev ibarakaiev changed the title Fix/join on demand sync initialization fix: ensure sync is started for on-demand collections in join queries Dec 29, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 29, 2025

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1076

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1076

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1076

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1076

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1076

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1076

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1076

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1076

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1076

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1076

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1076

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1076

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1076

commit: c287949

@ibarakaiev ibarakaiev marked this pull request as draft December 29, 2025 21:06
@ibarakaiev ibarakaiev force-pushed the fix/join-on-demand-sync-initialization branch from b17b374 to 794f21a Compare December 29, 2025 22:21
When using on-demand sync collections (e.g., Electric with offset: 'now'),
join queries were not receiving initial data for "lazy" aliases.

The issue was that subscribeToMatchingChanges() only called requestSnapshot()
when includeInitialState was true. But for lazy aliases in joins,
includeInitialState is false (to optimize data loading). However, on-demand
collections still need requestSnapshot() to trigger the sync layer.

This fix always calls requestSnapshot({}) in subscribeToMatchingChanges(),
ensuring all on-demand collection aliases properly load their initial state.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ibarakaiev ibarakaiev force-pushed the fix/join-on-demand-sync-initialization branch from 98a07e6 to 2ed70ce Compare December 29, 2025 22:35
@ibarakaiev
Copy link
Contributor Author

Closing as it appears to be more involved than a one-line fix, opening an issue instead #1077.

@ibarakaiev ibarakaiev closed this Dec 29, 2025
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.

1 participant