Skip to content

Commit 43c43a3

Browse files
committed
refactor: cacheTime-zero
weird edge case: the previous logic was instantly removing the query _while_ it was still fetching, which is something we likely don't want. The data will stay in the currentQuery of the observer if the observer unsubscribes but still exists, and a new subscription will pick it up, unless the query was explicitly cancelled or the abort signal was consumed.
1 parent 9875029 commit 43c43a3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/core/tests/query.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
onlineManager,
1414
QueryFunctionContext,
1515
} from '../..'
16+
import { waitFor } from '@testing-library/react'
1617

1718
describe('query', () => {
1819
let queryClient: QueryClient
@@ -472,7 +473,6 @@ describe('query', () => {
472473
})
473474

474475
test('queries with cacheTime 0 should be removed immediately after unsubscribing', async () => {
475-
const consoleMock = mockConsoleError()
476476
const key = queryKey()
477477
let count = 0
478478
const observer = new QueryObserver(queryClient, {
@@ -486,13 +486,12 @@ describe('query', () => {
486486
})
487487
const unsubscribe1 = observer.subscribe()
488488
unsubscribe1()
489-
await sleep(10)
489+
await waitFor(() => expect(queryCache.find(key)).toBeUndefined())
490490
const unsubscribe2 = observer.subscribe()
491491
unsubscribe2()
492-
await sleep(10)
493-
expect(count).toBe(2)
494-
expect(queryCache.find(key)).toBeUndefined()
495-
consoleMock.mockRestore()
492+
493+
await waitFor(() => expect(queryCache.find(key)).toBeUndefined())
494+
expect(count).toBe(1)
496495
})
497496

498497
test('should be garbage collected when unsubscribed to', async () => {

0 commit comments

Comments
 (0)