Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): keep garbage collecting an unobserved query after it is reset #12712

Openmgarcia-improving(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12712/headopened View on GitHub

Showing 3 changed files with 22 additions and 0 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/reset-query-keeps-gc.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-core': patch
+---
+​
+fix(query-core/query): keep garbage collecting an unobserved query after it is reset instead of leaving it in the cache without a timer
12 additions and 0 deletionspackages/query-core/src/__tests__/cacheGc.test.tsxModified
View file
@@ -90,6 +90,18 @@
expect(vi.getTimerCount()).toBe(0)
})
​
+ it('keeps garbage collecting an unobserved query that is reset', async () => {
+ const queryKey = ['reset']
+ await client.query({ queryKey, queryFn: () => Promise.resolve('data') })
+ expect(vi.getTimerCount()).toBe(1)
+​
+ await client.resetQueries({ queryKey })
+​
+ expect(vi.getTimerCount()).toBe(1)
+ vi.advanceTimersByTime(1000)
+ expect(client.getQueryCache().getAll()).toHaveLength(0)
+ })
+​
it('clears a timer scheduled by an abort listener during removal', async () => {
const observer = new QueryObserver(client, {
queryKey: ['aborted'],
5 additions and 0 deletionspackages/query-core/src/query.tsModified
View file