Skip to content

Conversation

obeattie
Copy link
Contributor

@obeattie obeattie commented Sep 3, 2025

Previously, when creating a collection from a TanStack Query that already had data, the collection would remain stuck in the loading state until the query refreshed. This happens because QueryObserver only invokes its callback on changes, not when attaching to an already-loaded query.

The issue was especially visible for me with Fast Refresh: working locally, after a hot reload, all query state disappeared until the next time the queries refreshed.

This change makes the callback fire immediately with the current query state when we set up the observer, so collections correctly initialize with existing data. (As far as I could tell, QueryObserver doesn’t provide a built-in way to fire the callback automatically with initial state.)

Copy link

changeset-bot bot commented Sep 3, 2025

🦋 Changeset detected

Latest commit: 19b9f84

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/query-db-collection Patch

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

Copy link

pkg-pr-new bot commented Sep 3, 2025

More templates

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@495

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@495

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@495

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@495

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@495

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@495

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@495

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@495

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@495

commit: 19b9f84

Copy link
Collaborator

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! It occurred to me the other day that we need to handle this so glad you saw it and fixed it!

@KyleAMathews KyleAMathews merged commit 03c529b into TanStack:main Sep 3, 2025
6 checks passed
@github-actions github-actions bot mentioned this pull request Sep 3, 2025
@obeattie obeattie deleted the query-race branch September 4, 2025 09:01
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.

2 participants