Skip to content

Observer holding on to old queryClient when client changes in QueryClientProvider #5458

@tonyxiao

Description

@tonyxiao

Describe the bug

In our app we allow user to switch between workspaces, and when they do we want an entirely different set of query cache / query client combo to isolate the data between workspaces. However simply changing the client provided to QueryClientProvider does not cause queries to refetch. Even manually calling refetch doesn't fully resolve the issue because the Observer has a constant reference to the previous QueryClient that does not update.

See trpc/trpc#4153 (comment) for additional context

Your minimal, reproducible example

https://github.com/tonyxiao/next-turbopack-example/blob/main/packages/app1/app/debug/page.tsx

Steps to reproduce

  1. Type into the slug field to cause queryClient to change
  2. Notice that value of res.data stays the same

Expected behavior

I would expect 1) All the queries to refetch and 2) Either new observers to be created or for the existing observer to update their query client reference.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

All platforms

Tanstack Query adapter

None

TanStack Query version

4.29.7

TypeScript version

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions