Skip to content

Vue SSR memory leak #9362

Open
Open
@escaton

Description

@escaton

Describe the bug

Hello, I'm having the same issue as one reported here #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions