-
Notifications
You must be signed in to change notification settings - Fork 98
fix query collection .preload()
#635
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
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: |
Size Change: 0 B Total Size: 74.1 kB ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 1.44 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
staleTime
behavior by:startSync=false
ANDsubscriberCount=0
staleTime
/gcTime
semanticsThe 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
/false
collection.subscriberCount
=0
queryFn
never 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 thestaleTime
behavior 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.