Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): prevent residual gc timers on removed cache entries #12664

ClosedJonathanHerSa(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/12664/headopened View on GitHub

Showing 6 changed files with 47 additions and 0 deletions (loading 3).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/prevent-residual-gc-timers.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-core': patch
+---
+​
+Prevent residual garbage-collection timers from remaining active or being rescheduled after entries are removed or destroyed.
32 additions and 0 deletionspackages/query-core/src/__tests__/mutationCache.test.tsxModified
View file
@@ -630,5 +630,37 @@
​
unsubscribe()
+​
+ it('should destroy mutation when removing it', () => {
+ const testCache = new MutationCache()
+ const testClient = new QueryClient({ mutationCache: testCache })
+​
+ const mutation = testCache.build(testClient, {
+ mutationFn: () => Promise.resolve('data'),
+ })
+​
+ const destroySpy = vi.spyOn(mutation, 'destroy')
+ testCache.remove(mutation)
+ expect(destroySpy).toHaveBeenCalledTimes(1)
+ })