Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeQueries unexpectedly detaches useQuery from re-rendering when the underlying data changes #8597

Open
codenothing opened this issue Jan 28, 2025 · 0 comments

Comments

@codenothing
Copy link

codenothing commented Jan 28, 2025

Describe the bug

Not sure if this is either a bug or just missing documentation, but essentially if you call removeQueries, and another component has useQuery mounted with the same key, it will no longer re-render when new data is set to that key.

The only way to "re-attach" that useQuery instance to the queryKey is to get the component to re-render

Your minimal, reproducible example

https://stackblitz.com/edit/removequeries-detachment-query-6y1qnf2s?file=src%2Findex.tsx

Steps to reproduce

  1. Setup parent component with a listener on useQuery({queryKey: ['my-key']})
  2. Add action action to child component that updates the value for my-key and refetches
  3. Add action button to child component that calls removeQueries({queryKey: ['my-key']})
  4. Click the actions to see the behavior.

Expected behavior

I would expect a refetch to update caches across all components. If that's not the expected behavior for removeQueries, may want to update the docs to reflect that

How often does this bug happen?

Every time

Screenshots or Videos

Screen.Recording.2025-01-28.at.11.22.11.AM.mov

Platform

  • OS: macOS 15.2
  • Browser: Chrome 132.0.6834.111

Tanstack Query adapter

react-query

TanStack Query version

4.3

TypeScript version

5.4

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant