-
Notifications
You must be signed in to change notification settings - Fork 152
fix: ensure sync is started for on-demand collections in join queries #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ibarakaiev
wants to merge
4
commits into
TanStack:main
from
ibarakaiev:fix/join-on-demand-sync-initialization
Closed
fix: ensure sync is started for on-demand collections in join queries #1076
ibarakaiev
wants to merge
4
commits into
TanStack:main
from
ibarakaiev:fix/join-on-demand-sync-initialization
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 detectedLatest commit: c287949 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
b17b374 to
794f21a
Compare
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>
98a07e6 to
2ed70ce
Compare
Contributor
Author
|
Closing as it appears to be more involved than a one-line fix, opening an issue instead #1077. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:offset: 'now'and only receive changes from when sync starts, not historical datarequestSnapshot()to fetch matching rowsstartSyncImmediate(), the collection stays idle andrequestSnapshot()has nothing to work withThe fix adds a
collection.startSyncImmediate()call insubscribeToAllCollections()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