From 9c76dd0fbd20680192ae3bff50680d4bb09068ad Mon Sep 17 00:00:00 2001 From: Ochieng Paul Date: Sun, 26 Jan 2025 23:54:38 +0300 Subject: [PATCH] updates --- website2/src/hooks/swrConfig.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/website2/src/hooks/swrConfig.ts b/website2/src/hooks/swrConfig.ts index 4cdea83587..e48c6edcd9 100644 --- a/website2/src/hooks/swrConfig.ts +++ b/website2/src/hooks/swrConfig.ts @@ -1,9 +1,11 @@ -export const swrOptions = { +import type { SWRConfiguration } from 'swr'; + +export const swrOptions: SWRConfiguration = { // Revalidate data on focus of the window (when the user returns to the tab) - revalidateOnFocus: true, + revalidateOnFocus: false, // Revalidate data when the browser reconnects to the network - revalidateOnReconnect: true, + revalidateOnReconnect: false, // Disable automatic refreshing at intervals refreshInterval: 0, @@ -13,6 +15,15 @@ export const swrOptions = { // Retry fetching on error settings shouldRetryOnError: true, - errorRetryCount: 3, + errorRetryCount: 2, // This will result in 3 total attempts (initial + 2 retries) errorRetryInterval: 5000, + + // Custom onErrorRetry function to stop retrying after 3 attempts + onErrorRetry: (error, key, config, revalidate, { retryCount }) => { + // Only retry up to 2 times (3 total attempts) + if (retryCount >= 2) return; + + // Retry after 5 seconds + setTimeout(() => revalidate({ retryCount: retryCount + 1 }), 5000); + }, };