From 8a4dd2cb324a9b0344a845628d372f54fd2ef374 Mon Sep 17 00:00:00 2001 From: Jack Ellis Date: Fri, 15 May 2020 11:36:53 +0100 Subject: [PATCH 1/2] fix: clear cache timeouts calling queryCache.clear() was empting the queries object but not tearing any of them down this commit adds a clear method to the individual queries, which cancels timeouts and promises queryCache.clear now loops through the queries and clears each one I've also update the return type of queryCache.clear as it doesn't actually return anything --- src/queryCache.js | 10 ++++++++++ types/index.d.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/queryCache.js b/src/queryCache.js index 79a7467957..43a059cf85 100644 --- a/src/queryCache.js +++ b/src/queryCache.js @@ -84,6 +84,7 @@ export function makeQueryCache() { } cache.clear = () => { + Object.values(cache.queries).forEach(query => query.clear()) cache.queries = {} notifyGlobalListeners() } @@ -516,6 +517,15 @@ export function makeQueryCache() { query.scheduleStaleTimeout() } + query.clear = () => { + clearTimeout(query.staleTimeout) + clearTimeout(query.cacheTimeout) + if (query.cancelQueries) { + query.cancelQueries() + } + query.cancelled = cancelledError + } + return query } diff --git a/types/index.d.ts b/types/index.d.ts index 09a8d43992..0edecdb7fc 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -593,6 +593,7 @@ export interface CachedQuery { setData( dataOrUpdater: unknown | ((oldData: unknown | undefined) => unknown) ): void + clear(): void } export interface QueryCache { @@ -701,7 +702,7 @@ export interface QueryCache { ): void isFetching: number subscribe(callback: (queryCache: QueryCache) => void): () => void - clear(): Array> + clear(): void } export const queryCache: QueryCache From 47628eb3e2fa0cdb168b9d188b488d5319a0b3c9 Mon Sep 17 00:00:00 2001 From: Jack Ellis Date: Sat, 16 May 2020 07:30:40 +0100 Subject: [PATCH 2/2] fixup! fix: clear cache timeouts --- src/queryCache.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/queryCache.js b/src/queryCache.js index 43a059cf85..4dc47f72cf 100644 --- a/src/queryCache.js +++ b/src/queryCache.js @@ -520,10 +520,7 @@ export function makeQueryCache() { query.clear = () => { clearTimeout(query.staleTimeout) clearTimeout(query.cacheTimeout) - if (query.cancelQueries) { - query.cancelQueries() - } - query.cancelled = cancelledError + query.cancel() } return query