From afcf28648e3e0240ad6da5f8aea23dc864bbad3b Mon Sep 17 00:00:00 2001 From: Mike Goodfellow Date: Tue, 12 Dec 2023 10:20:41 +0000 Subject: [PATCH] Initialise nextFocusRevalidatedAt on mount --- core/src/use-swr.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/use-swr.ts b/core/src/use-swr.ts index 8480ea805..f783d54cd 100644 --- a/core/src/use-swr.ts +++ b/core/src/use-swr.ts @@ -574,9 +574,15 @@ export const useSWRHandler = ( const softRevalidate = revalidate.bind(UNDEFINED, WITH_DEDUPE) + let nextFocusRevalidatedAt = 0 + + if (getConfig().revalidateOnFocus) { + const initNow = Date.now() + nextFocusRevalidatedAt = initNow + getConfig().focusThrottleInterval + } + // Expose revalidators to global event listeners. So we can trigger // revalidation from the outside. - let nextFocusRevalidatedAt = 0 const onRevalidate = ( type: RevalidateEvent, opts: {