From 3b04acfb2246947afca7a5f310ad9aafea089e1d Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 27 Feb 2023 20:47:10 +0100 Subject: [PATCH] Always assume subscriptions will return sub count from current key (#2460) --- subscription/index.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/subscription/index.ts b/subscription/index.ts index 922d265fc..f1fe82421 100644 --- a/subscription/index.ts +++ b/subscription/index.ts @@ -86,14 +86,13 @@ export const subscription = ((useSWRNext: SWRHook) => return () => { // Prevent frequent unsubscribe caused by unmount setTimeout(() => { - // TODO: Throw error during development if count is undefined. - const count = subscriptions.get(subscriptionKey) - if (count == null) return + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const count = subscriptions.get(subscriptionKey)! - 1 - subscriptions.set(subscriptionKey, count - 1) + subscriptions.set(subscriptionKey, count) // Dispose if it's the last one. - if (count === 1) { + if (!count) { const dispose = disposers.get(subscriptionKey) dispose?.() }