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

refetchQueries with explicit list refetches inactive queries in React StrictMode #12228

Open
levrik opened this issue Dec 16, 2024 · 3 comments

Comments

@levrik
Copy link
Contributor

levrik commented Dec 16, 2024

Issue Description

refetchQueries on useMutation results in inactive queries to be refetched as well if given an explicit list of queries.

As explained over at #11894 (comment) by @jerelmiller, Apollo Client seems to rely on inactive queries to be removed from queryManager.queries for refetchQueries. In StrictMode queries get inserted twice into queryManager.queries and only 1 instance gets removed on unmount of the parent component of useQuery. Since queryManager.getObservableQueries() gets passed an explicit list by queryManager.refetchQueries(), it simply returns all observables for given queries regardless of active/inactive state, resulting in also inactive queries to be refetched.

This is specifically annoying if you have a query like project(id: '...') and expect to only refetch the currently opened project and not all which have been opened in the past.

Link to Reproduction

https://codesandbox.io/p/devbox/recursing-surf-tmwx9d

Reproduction Steps

  1. Open DevTools
    You should see resolve `people(filter: undefined)` in logs
  2. Click "Dummy Query" link
    You should see resolve `people(filter: dummy)` in logs
  3. Click "Home" link
  4. Add a name through the form
    You should see resolve `people(filter: undefined)` and resolve `people(filter: dummy)` in logs

@apollo/client version

3.12.3

Copy link

triagster bot commented Dec 16, 2024

No dupes found!

@levrik levrik changed the title refetchQueries with explicit list broken in React StrictMode refetchQueries with explicit list refetches inactive queries in React StrictMode Dec 16, 2024
@jerelmiller
Copy link
Member

@levrik I believe #11914 also describes this same issue which will likely be fixed by #11925.

I'll do by best to take some time this week to rereview PR and see if we can get it in a patch. Please follow progress on that PR for updates.

@levrik
Copy link
Contributor Author

levrik commented Dec 16, 2024

@jerelmiller Ah, I saw that issue but thought it's different as calling resetStore seemed to be important there which I don't do. Will keep an eye on that PR.

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

No branches or pull requests

2 participants