feat(query-db-collection): expose query state from QueryObserver#712
Closed
KyleAMathews wants to merge 3 commits intomainfrom
Closed
feat(query-db-collection): expose query state from QueryObserver#712KyleAMathews wants to merge 3 commits intomainfrom
KyleAMathews wants to merge 3 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: e92c3f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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: 77.6 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 2.89 kB ℹ️ View Unchanged
|
samwillis
reviewed
Oct 31, 2025
Collaborator
samwillis
left a comment
There was a problem hiding this comment.
looking ok, but question on the api design
Comment on lines
178
to
204
| /** | ||
| * Check if the query is currently fetching data (including background refetches). | ||
| * Returns true during both initial fetches and background refetches. | ||
| */ | ||
| isFetching: () => boolean | ||
| /** | ||
| * Check if the query is currently refetching data in the background. | ||
| * Returns true only during background refetches (not initial fetch). | ||
| */ | ||
| isRefetching: () => boolean | ||
| /** | ||
| * Check if the query is loading for the first time (no data yet). | ||
| * Returns true only during the initial fetch before any data is available. | ||
| */ | ||
| isLoading: () => boolean | ||
| /** | ||
| * Get the timestamp (in milliseconds since epoch) when the data was last successfully updated. | ||
| * Returns 0 if the query has never successfully fetched data. | ||
| */ | ||
| dataUpdatedAt: () => number | ||
| /** | ||
| * Get the current fetch status of the query. | ||
| * - 'fetching': Query is currently fetching | ||
| * - 'paused': Query is paused (e.g., network offline) | ||
| * - 'idle': Query is not fetching | ||
| */ | ||
| fetchStatus: () => `fetching` | `paused` | `idle` |
Collaborator
There was a problem hiding this comment.
Do we want these to be getters rather than methods?
Collaborator
Author
There was a problem hiding this comment.
oh yeah — Claude was just copying the other util functions but TanStack Query & DB generally both use getters so let's do the change along with the other utils.
BREAKING CHANGE: Query state utilities are now accessed as properties instead of function calls, aligning with TanStack Query's API patterns for a more intuitive developer experience. Changed utilities: - lastError() → lastError - isError() → isError - errorCount() → errorCount - isFetching() → isFetching - isRefetching() → isRefetching - isLoading() → isLoading - dataUpdatedAt() → dataUpdatedAt - fetchStatus() → fetchStatus New features: - Exposes TanStack Query's QueryObserver state through utility getters - Enables "Last updated" UI patterns and background fetch indicators - Provides insight into sync behavior beyond error states Migration: Remove parentheses when accessing these properties Example: collection.utils.isFetching() → collection.utils.isFetching Resolves user request from Discord where status is always 'ready' after initial load, making it impossible to know if background refetches are happening. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5902599 to
bd32d34
Compare
- Merged latest changes from origin/main - Resolved conflicts in query.ts: - Combined queryObserver reference storage with query state initialization - Made clearError async to match main branch changes - Fixed test file to use property access instead of function calls for getters - Note: Some test failures to be investigated - likely timing issues from merge
- Fixed type compatibility issues by using UtilsRecord as TUtils parameter in return types - Removed duplicate queryState initialization - Converted all test function calls to property access for getters - Ran prettier to format code - Reduced test failures from 15 to 13 Type errors: 0 remaining Test status: 13 failures (down from 15), 60 passing
Collaborator
Author
|
Closed in favor of #742 |
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.
Adds new utility methods to QueryCollectionUtils to expose TanStack Query's QueryObserver state, addressing user request for visibility into sync status:
New utils exposed:
This allows users to:
Resolves user request from Discord where status is always 'ready' after initial load, making it impossible to know if background refetches are happening.
🤖 Generated with Claude Code
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact