From ecdbb0efb652089a14004a426ef0b3cf472f3759 Mon Sep 17 00:00:00 2001 From: Matt Sutkowski Date: Sat, 22 Jan 2022 09:04:19 -0800 Subject: [PATCH] Address feedback --- packages/toolkit/src/query/core/buildMiddleware/polling.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/toolkit/src/query/core/buildMiddleware/polling.ts b/packages/toolkit/src/query/core/buildMiddleware/polling.ts index a48527efae..a30f3f4fe9 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/polling.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/polling.ts @@ -103,13 +103,13 @@ export const build: SubMiddlewareBuilder = ({ } const lowestPollingInterval = findLowestPollingInterval(subscriptions) - const currentPoll = currentPolls[queryCacheKey] if (!Number.isFinite(lowestPollingInterval)) { cleanupPollForKey(queryCacheKey) return } + const currentPoll = currentPolls[queryCacheKey] const nextPollTimestamp = Date.now() + lowestPollingInterval if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) { @@ -119,7 +119,9 @@ export const build: SubMiddlewareBuilder = ({ function cleanupPollForKey(key: string) { const existingPoll = currentPolls[key] - existingPoll?.timeout && clearTimeout(existingPoll.timeout) + if (existingPoll?.timeout) { + clearTimeout(existingPoll.timeout) + } delete currentPolls[key] }