From ba1ba8a116fa71f100515ea6a7a060eb9a286cef Mon Sep 17 00:00:00 2001 From: manceau-jb Date: Wed, 28 Sep 2022 21:04:42 +0200 Subject: [PATCH] Fix invalidateTags --- .../buildMiddleware/invalidationByTags.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts b/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts index d434f4d2c2..83e7c21afa 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/invalidationByTags.ts @@ -70,18 +70,18 @@ export const build: SubMiddlewareBuilder = ({ const valuesArray = Array.from(toInvalidate.values()) for (const { queryCacheKey } of valuesArray) { const querySubState = state.queries[queryCacheKey] - const subscriptionSubState = state.subscriptions[queryCacheKey] || {} + const subscriptionSubState = state.subscriptions[queryCacheKey] ?? {} - if (!querySubState) continue - - if (Object.keys(subscriptionSubState).length === 0) { - mwApi.dispatch( - removeQueryResult({ - queryCacheKey: queryCacheKey as QueryCacheKey, - }) - ) - } else if (querySubState.status !== QueryStatus.uninitialized) { - mwApi.dispatch(refetchQuery(querySubState, queryCacheKey)) + if (querySubState) { + if (Object.keys(subscriptionSubState).length === 0) { + mwApi.dispatch( + removeQueryResult({ + queryCacheKey: queryCacheKey as QueryCacheKey, + }) + ) + } else if (querySubState.status !== QueryStatus.uninitialized) { + mwApi.dispatch(refetchQuery(querySubState, queryCacheKey)) + } } } })