Skip to content

invalidateQueries does not refetch active queries after queryClient.clear() #4886

@itsramiel

Description

@itsramiel

Describe the bug

In my app when the user changes the language, I clear the query client with queryClient.clear() because I want to remove any cache since it has data with invalid language, but when I later invalidateQueries with queryClient.invalidateQueries([queryKey]) it does not invalidate the query.

This only happens after clearing the query client

Your minimal, reproducible example

https://codesandbox.io/s/late-river-h8mt4h?file=/src/App.js

Steps to reproduce

  1. press on invaldate and notice how it calls the api
  2. press on clear(not sure why it does not refetch but that is not the bug I am talking about)
  3. press on invalidate and it will no longer work

Expected behavior

I expect query invalidate to work after clearing the query client just as it was before clearing it

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: Macos
  • Browser: Firefox

Also on iphone. I experience it on my mobile app with react native

TanStack Query version

4.23.0

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