Skip to content

Conversation

obeattie
Copy link
Contributor

Previously, query-db-collection created a persistent QueryObserver that remained subscribed throughout the collection's lifecycle, breaking TanStack Query's staleTime behavior. From Query's perspective, there was always an "active" observer, so queries never went inactive and staleTime never applied.

This PR fixes the issue by subscribing/unsubscribing the QueryObserver based on collection subscriber count. When no components are using the collection, the query becomes inactive. When the collection is observed again, TanStack Query can then refetch automatically. So query-db-collection now behaves similarly to standard TanStack Query hooks for caching and staleness.

Fixes #348.

When a collection backed by a TanStack Query has no active subscribers,
automatically unsubscribe from the query.
Copy link

changeset-bot bot commented Aug 27, 2025

⚠️ No Changeset found

Latest commit: c1d5eb9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

Fix staleTime behavior in query-db-collection by tracking component subscriptions
1 participant