From bf61090b5ab2b26b03c07e2bd94770eab3eb0bbb Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 Mar 2025 02:58:59 +0530 Subject: [PATCH 1/2] feat: added cache clear and refresh with session limit --- frontend/src/main.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index f4789b3eb..a2fe04656 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -25,6 +25,34 @@ import "./translation"; // Create a new router instance NProgress.configure({ showSpinner: false }); +window.addEventListener("vite:preloadError", async (event) => { + event.preventDefault(); + // Get current count from session storage or initialize to 0 + const reloadCount = parseInt(sessionStorage.getItem("vitePreloadErrorCount") || "0", 10); + + // Check if we've already tried 3 times + if (reloadCount >= 3) { + console.warn("Vite preload has failed multiple times. Stopping automatic reload."); + // Optionally show a user-facing message here + return; + } + + try { + if ("caches" in window) { + const keys = await caches.keys(); + await Promise.all(keys.map((key) => caches.delete(key))); + } + } catch (cleanupError) { + console.error(cleanupError); + } + // + // Increment and save the counter + sessionStorage.setItem("vitePreloadErrorCount", (reloadCount + 1).toString()); + + console.log(`Reloading page (attempt ${reloadCount + 1} of 3)...`); + window.location.reload(); // for example, refresh the page +}); + const router = createRouter({ routeTree, context: { serverConfig: null, queryClient }, From e530b7a7889a03ba5f3f682def61de39f92058eb Mon Sep 17 00:00:00 2001 From: = Date: Fri, 21 Mar 2025 02:59:44 +0530 Subject: [PATCH 2/2] feat: reduced to two --- frontend/src/main.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index a2fe04656..779c21bd8 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -31,7 +31,7 @@ window.addEventListener("vite:preloadError", async (event) => { const reloadCount = parseInt(sessionStorage.getItem("vitePreloadErrorCount") || "0", 10); // Check if we've already tried 3 times - if (reloadCount >= 3) { + if (reloadCount >= 2) { console.warn("Vite preload has failed multiple times. Stopping automatic reload."); // Optionally show a user-facing message here return; @@ -49,7 +49,7 @@ window.addEventListener("vite:preloadError", async (event) => { // Increment and save the counter sessionStorage.setItem("vitePreloadErrorCount", (reloadCount + 1).toString()); - console.log(`Reloading page (attempt ${reloadCount + 1} of 3)...`); + console.log(`Reloading page (attempt ${reloadCount + 1} of 2)...`); window.location.reload(); // for example, refresh the page });