Skip to content

Commit

Permalink
bug: reset query via query instead of using resetQueries on client
Browse files Browse the repository at this point in the history
  • Loading branch information
kalijonn committed Sep 15, 2024
1 parent 5b9b962 commit cf6ef76
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions __tests__/atomWithQuery_spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 1 addition & 2 deletions src/baseAtomWithQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
Expand Down

0 comments on commit cf6ef76

Please sign in to comment.