nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: tannerlinsley/react-query
Pull request #1934 (2021-03-09 16:38:56)

fix: Do not refetch active queries if "refetchActive" is set to "false"
This PR fixes the issue reported here: https://github.com/tannerlinsley/react-query/issues/1931

When a query was invalidated and `refetchActive` was set to `false`, the query would still be refetched, unless `refetchInactive` was set to `true`. 

The PR fixes this by not letting the `inactive` option in the query filters default to `false` if it was actually `undefined`.

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/tannerlinsley/react-query/GTY3QKs3caCoCCU2DsfWyMJwB4rt](https://vercel.com/tannerlinsley/react-query/GTY3QKs3caCoCCU2DsfWyMJwB4rt)  
✅ Preview: *In Progress*


DerJacques: @tannerlinsley Should I do anything else to have this PR merged? 😊

Patch:
diff --git a/src/core/queryClient.ts b/src/core/queryClient.ts
index a7230fbfb..cc7c5427b 100644
--- a/src/core/queryClient.ts
+++ b/src/core/queryClient.ts
@@ -207,7 +207,7 @@ export class QueryClient {
     const refetchFilters: QueryFilters = {
       ...filters,
       active: filters.refetchActive ?? true,
-      inactive: filters.refetchInactive ?? false,
+      inactive: filters.refetchInactive,
     }
 
     return notifyManager.batch(() => {


Test patch:
diff --git a/src/core/tests/queryClient.test.tsx b/src/core/tests/queryClient.test.tsx
index f34d7a080..016324bf2 100644
--- a/src/core/tests/queryClient.test.tsx
+++ b/src/core/tests/queryClient.test.tsx
@@ -550,6 +550,22 @@ describe('queryClient', () => {
       expect(queryFn1).toHaveBeenCalledTimes(1)
       expect(queryFn2).toHaveBeenCalledTimes(1)
     })
+
+    test('should not refetch active queries when "refetchActive" is false', async () => {
+      const key1 = queryKey()
+      const queryFn1 = jest.fn()
+      await queryClient.fetchQuery(key1, queryFn1)
+      const observer = new QueryObserver(queryClient, {
+        queryKey: key1,
+        staleTime: Infinity,
+      })
+      const unsubscribe = observer.subscribe()
+      queryClient.invalidateQueries(key1, {
+        refetchActive: false,
+      })
+      unsubscribe()
+      expect(queryFn1).toHaveBeenCalledTimes(1)
+    })
   })
 
   describe('resetQueries', () => {