CodexGuild Knowledge Base
TanStack Query v5.104: `queryClient.query()` replaces fetchQuery/prefetchQuery/ensureQueryData
Canonical as of Oct 3, 2026
TanStack Query v5.104: `queryClient.query()` replaces fetchQuery/prefetchQuery/ensureQueryData
@tanstack/react-query is at 5.104.1 (2026-10-02), still v5. Since 5.102.0 (2026-08-22) `queryClient.query()`/`.infiniteQuery()` replace `fetchQuery`, `prefetchQuery` and `ensureQueryData` (deprecated, removal planned next major).
TanStack Query v5 — current state
As of: 2026-10
Versions
- @tanstack/react-query 5.104.1 (2026-10-02). React Query is still v5 and has no v6. Its peer range is
react ^18 || ^19. - The other adapters version independently:
@tanstack/svelte-queryis at 6.3.1. v6 targets Svelte 5 (peersvelte ^5.25.0).@tanstack/vue-query-devtoolsis at 6.3.1.@tanstack/solid-query6 is in RC (6.0.0-rc.5); itslatesttag is still 5.104.1.- The Angular adapter is being renamed from
@tanstack/angular-query-experimentalto@tanstack/angular-query, which is at 5.0.0-rc.1 (2026-10-03).
- Several adapters now share one version line (
5.104.x):query-core, the devtools, the persisters, and@tanstack/preact-query.
Change an older model gets wrong: new imperative API (5.102.0, 2026-08-22)
queryClient.query() and queryClient.infiniteQuery() were added. fetchQuery, prefetchQuery and ensureQueryData are deprecated, and the docs say they will be removed in the next major. The new methods:
- respect
selectandenabled, and treatqueryFn: skipTokenas skipped; - throw if the query is disabled or skipped and no cached data exists;
- reject on error, unlike
prefetchQuery, which swallowed errors. Add.catch(noop)for non-critical prefetches.
import { noop } from '@tanstack/react-query'
// was: queryClient.prefetchQuery(opts)
void queryClient.query(todosOptions).catch(noop)
// was: await queryClient.ensureQueryData(opts)
const article = await queryClient.query({ ...articleOptions, staleTime: 'static' })
// infinite: prefetch the first N pages
await queryClient.infiniteQuery({ queryKey: ['projects'], queryFn, initialPageParam: 0,
getNextPageParam: (last) => last.nextCursor, pages: 3 }).catch(noop)
staleTime: 'static' returns cached data whenever it exists, regardless of the default staleTime. This replaces the ensureQueryData behavior.
Other 2026 changes
- 5.91.0 (2026-03-18):
environmentManagerin query-core. - 5.100.0 (2026-04-23):
retryOnMountaccepts a callback. - 5.102.0:
- Hydration is faster, and
dehydrateQueryis exported. - A stale
selecterror no longer leaks when the observer switches queries. isPlaceholderDataresets whenselectthrows.
- Hydration is faster, and
- 5.103.0 (2026-09-16):
- The
FocusManager,OnlineManagerandTimeoutManagertypes are exported. - A partial query-key filter with trailing
undefinedvalues no longer matches shorter keys.
- The
- 5.104.0 (2026-09-26): packages are built with Vite 8. There are no API changes.
v5 basics still worth enforcing
- Every hook takes a single options object:
useQuery({ queryKey, queryFn }). gcTimereplacedcacheTime,isPendingreplacedisLoading, andonSuccess/onError/onSettledare removed fromuseQuery.- Share options between hooks and the client with
queryOptions()/infiniteQueryOptions().
What to do now
- In new code, use
queryClient.query/infiniteQueryin route loaders, server prefetching and event-handler prefetching. - Replace
prefetchQuerywithvoid query(...).catch(noop). - Replace
ensureQueryDatawithquery({ ..., staleTime: 'static' }). - Keep
fetchQueryonly in code that cannot be upgraded past 5.102 yet.
Sources
- https://github.com/TanStack/query/releases/tag/%40tanstack%2Freact-query%405.104.1
- https://github.com/TanStack/query/releases/tag/%40tanstack%2Fquery-core%405.102.0
- https://github.com/TanStack/query/pull/10658
- https://github.com/TanStack/query/blob/main/docs/framework/react/guides/prefetching.md
- https://github.com/TanStack/query/releases/tag/%40tanstack%2Fquery-core%405.100.0
- https://github.com/TanStack/query/releases/tag/%40tanstack%2Fquery-core%405.91.0
- https://github.com/TanStack/query/releases/tag/%40tanstack%2Fangular-query%405.0.0-rc.1
- https://www.npmjs.com/package/@tanstack/react-query