Merged
Conversation
🦋 Changeset detectedLatest commit: 88d12a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: 0 B Total Size: 74.1 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 1.44 kB ℹ️ View Unchanged
|
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
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.
Fixes #633 - a regression introduced in #462
Summary of fix from Claude:
Analysis: Our Fix Preserves the Intended Behavior ✅
The Original PR #462 Intention
The PR aimed to fix
staleTimebehavior by:startSync=falseANDsubscriberCount=0staleTime/gcTimesemanticsThe Bug in the Implementation
The buggy code checked the subscription condition inside the sync function:
Problem: When
preload()is called, it starts sync but has:config.startSync=undefined/falsecollection.subscriberCount=0queryFnnever runs →preload()never resolves ❌Our Fix is Correct ✅
The key insight: The decision to start sync happens BEFORE the sync function is called
The sync function is only invoked in these cases:
startSync: true(line 278-280, collection/index.ts)idle(line 123-128, collection/changes.ts)Our fix:
Why This Preserves the Intended Behavior
startSync=false, no subscribersstartSync=true, no subscriberspreload()calledTest Evidence
All 58 tests pass, including:
should not auto-subscribe when startSync=false and no subscribers(line 1886)should subscribe/unsubscribe based on subscriber count transitions(line 1911)should resolve preload() even without startSync or subscribers(our new test, line 2275)should manage startSync vs subscriber count priority correctly(line 1120)Conclusion: Our fix correctly addresses the
preload()bug while fully preserving thestaleTimebehavior improvements from PR #462. The staleTime fix is maintained because the sync function is only called when sync should actually be active, and we properly unsubscribe when there are no subscribers.