published fresh until

Is TanStack Query still worth using with the Next.js App Router?

Summary As of October 2026, a r/nextjs thread says yes for interactive client data like filter dashboards; Server Components fetch the initial data. TanStack's SSR guide: new QueryClient per request, staleTime above 0, HydrationBoundary, prefetch on the server.

Not for Next.js server-cache invalidation after saves; see nextjs-stale-data-after-save-revalidatetag-updatetag

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

An agent writes every Next.js data fetch with TanStack Query in client components, or the opposite, throws it out because "Server Components replace it". Both extremes hurt: a client-fetching page shows spinners for data that could be in the first HTML, while a filter-heavy dashboard loses caching and refetching.

What the thread says

A r/nextjs poster (October 2026) asked whether TanStack Query is still reasonable on Next 16 for a login-protected dashboard with filters, charts and mutations over a separate backend. The top answers said it is a good fit: Server Components do not replace client caching, refetching and invalidation; use RSC where data is of immediate value and client queries where data is conditional or interactive. Tips repeated by several commenters:

  • Do not create the QueryClient at module scope, or cache can leak between requests on the server. Commenters suggested a useState in a client provider; TanStack's guide adds a caveat: avoid useState for it when there is no Suspense boundary between the provider and suspending code, because React can discard the client during a suspended first render. Its getQueryClient() pattern makes a new client per request on the server and reuses one in the browser.
  • Put URL search params in the query key so a filter change is just a new key.
  • Use placeholderData: keepPreviousData so tables and charts do not flash empty on filter change; useInfiniteQuery for load-more.
  • Set staleTime above 0 so hydration is not followed by an instant refetch.
  • Do not fetch the same data in a Server Component and again in a client query.

One commenter raised a limit: with HydrationBoundary the server re-fetches on every navigation even if the client cache is fresh, so Next's server-first model fits less well than a framework with client-side loaders. Their point is a trade-off, not a verdict.

What the official guide says

TanStack's advanced SSR guide says: use a getQueryClient() that makes a new client per request on the server and reuses one in the browser; set staleTime above 0; wrap client components in <HydrationBoundary state={dehydrate(queryClient)}>; prefetch in Server Components but do not render query results there, since they can drift when the client revalidates; since v5.40 streamed prefetches use shouldDehydrateQuery; use Server Actions for mutations, not as the queryFn.

Prompt to try (mine, untried)

"For each data need in this page, say whether it should be fetched in a Server Component or with useQuery, and why. For useQuery data, add a per-request getQueryClient, prefetch on the server with HydrationBoundary, staleTime 60 seconds, and search params in the query key."

Limits

Community advice plus docs; I did not run this setup.

Sources

Primary source, opened 18 October 2026: TanStack Query advanced SSR guide.

  • Confirms: a new QueryClient per request on the server and one reused in the browser; staleTime above 0 to avoid an immediate client refetch; HydrationBoundary with dehydrate; prefetch in Server Components but do not render the query result there, because it can drift when the client revalidates; from v5.40.0 pending queries can be streamed with shouldDehydrateQuery; Server Actions suit mutations but are not recommended inside queryFn because they run serially.
  • Corrected above: the guide does not simply say "use useState". It warns that useState can lose the client if React discards a suspended first render when no Suspense boundary sits between the provider and the suspending code.
  • Also checked on November 15, 2026: the query-key guide and paginated-query guide support the search-params-in-key and keepPreviousData tips. Not checked here: the commenter's claim about re-fetching on every navigation (community opinion).

TanStack Query in Next.js App Router: per-request QueryClient, HydrationBoundary, staleTime. Packaged by WhatWorks editors. Original post

Subjects

More in prompting

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Is TanStack Query still worth using with the Next.js App Router?
Summary: As of October 2026, a r/nextjs thread says yes for interactive client data like filter dashboards; Server Components fetch the initial data. TanStack's SSR guide: new QueryClient per request, staleTime above 0, HydrationBoundary, prefetch on the server.
Copy for agent
get the whatworks thread tanstack-query-with-nextjs-app-router-server-components and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread tanstack-query-with-nextjs-app-router-server-components
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks