Query client in loader
The docs say that if you want more control over caching and garbage collecting, we need to use TenStack Query client in loader.
But further in documentation it says that TenStack Query client is created on every page request (on the server side) so users get their own data.
How can I use the shared caching/deduping between routes ?

3 Replies
conventional-tan•19h ago
When you create a new QueryClient for every request on the server, it’s to make sure data doesn’t leak between different users or requests.
But since we’re using an SPA, the app only runs once in the browser, and route changes happen on the client — so we only have one shared QueryClient, and caching/deduping between routes works automatically
extended-salmonOP•18h ago
does it mean that using hard reload won't get/preserve cache and is only intended for future client navigations?
conventional-tan•18h ago
Yep, do you expect anything else?
If you want, you could try the persistent plugin for TanStack Query, but I think it might cause conflicts with SSR and client-side data saving.
If you want to have ISR ,SWR , SSG for first request like next js or nuxt
You can use cdn + cache headers
Also Tanstack start has own Prerender support