refetchQueries
with explicit list refetches inactive queries in React StrictMode
#12228
Labels
refetchQueries
with explicit list refetches inactive queries in React StrictMode
#12228
Issue Description
refetchQueries
onuseMutation
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
forrefetchQueries
. In StrictMode queries get inserted twice intoqueryManager.queries
and only 1 instance gets removed on unmount of the parent component ofuseQuery
. SincequeryManager.getObservableQueries()
gets passed an explicit list byqueryManager.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
You should see
resolve `people(filter: undefined)`
in logsYou should see
resolve `people(filter: dummy)`
in logsYou should see
resolve `people(filter: undefined)`
andresolve `people(filter: dummy)`
in logs@apollo/client
version3.12.3
The text was updated successfully, but these errors were encountered: