Describe the bug#
Hello, I'm having the same issue as one reported here https://github.com/TanStack/query/issues/5296
But I do not use Nuxt, and so Nuxt specific features do not help me in this case — onScopeDestroy is not called in my almost vanilla (vite-ssr) SSR app, and so I got a leak of query observers.
The only non-conventional thing I do is: I want to manage the query cache myself, so I make it a singleton on the server, hoping that it will only contain the cached data. But turns out, it holds all the subscriptions from all queryObservers ever created on every request.
cc @DamianOsipiuk
Your minimal, reproducible example#
https://codesandbox.io/p/devbox/qm3xrt
Steps to reproduce#
npm run dev
Expected behavior#
There is a log indicating how many query observers are left after the renderToString on SSR, and currently that number is growing with every new request, while I'm expecting it to be zero.
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
node
Tanstack Query adapter#
None
TanStack Query version#
5.81.2
TypeScript version#
No response
Additional context#
No response
I realized that what I want is a
persister. Tried it with queryClient-per-request, and so far looks good for my SSR long term cache.