From cf6ef7656f2b3285c627ec306087efb2343b0827 Mon Sep 17 00:00:00 2001 From: kalijonn <43421621+kalijonn@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:23:06 +0530 Subject: [PATCH] bug: reset query via query instead of using resetQueries on client --- __tests__/atomWithQuery_spec.tsx | 4 ++-- src/baseAtomWithQuery.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/__tests__/atomWithQuery_spec.tsx b/__tests__/atomWithQuery_spec.tsx index 86de580..747d936 100644 --- a/__tests__/atomWithQuery_spec.tsx +++ b/__tests__/atomWithQuery_spec.tsx @@ -645,8 +645,8 @@ describe('error handling', () => { }) }) -// // Test for bug described here: -// // https://github.com/jotaijs/jotai-tanstack-query/issues/34 +// Test for bug described here: +// https://github.com/jotaijs/jotai-tanstack-query/issues/34 // Note: If error handling tests run after this test, they are failing. Not sure why. it('renews the result when the query changes and a non stale cache is available', async () => { const queryClient = new QueryClient({ diff --git a/src/baseAtomWithQuery.ts b/src/baseAtomWithQuery.ts index a6d254e..2aefea8 100644 --- a/src/baseAtomWithQuery.ts +++ b/src/baseAtomWithQuery.ts @@ -90,7 +90,6 @@ export function baseAtomWithQuery< } const dataAtom = atom((get) => { - const client = getQueryClient(get) const observer = get(observerAtom) const defaultedOptions = get(defaultedOptionsAtom) const result = observer.getOptimisticResult(defaultedOptions) @@ -104,7 +103,7 @@ export function baseAtomWithQuery< const unsubscribe = observer.subscribe(notifyManager.batchCalls(set)) return () => { if (observer.getCurrentResult().isError) { - client.resetQueries({ queryKey: observer.getCurrentQuery().queryKey }) + observer.getCurrentQuery().reset() } unsubscribe() }