Skip to content
Source
Sign inSign up
TanStack/query

Vue SSR memory leak #9362

Send to my agent
Closedescaton(GitHub profile, opens in a new tab) opened this issue 2 comments

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

  1. 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.

  2. I also had a leak in Nuxt SSR and found out that there are known issues in vue version 3.5. If you experience any, try v3.4.38 or the new v3.6.0-alpha. I tested both and it resolved my problems.

  3. TkDodo added labelsupstream

  4. TkDodo closed this

Sign in to join this conversation.