From ea2155c63574e5f3c6ef65008a66e214280cb7e0 Mon Sep 17 00:00:00 2001 From: Lotus Bot Date: Fri, 22 May 2026 02:31:54 -0400 Subject: [PATCH] fix: auto-reload on stale chunk load failure (vite:preloadError) When a new deploy lands while a tab is open, lazy-loaded chunks (like GifPicker) disappear because their content-hash filename changes. Vite dispatches a vite:preloadError event in this case. We reload once and clear the flag on successful load so future deploys can trigger again. --- src/index.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 79ef54b81..882d60492 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -68,6 +68,16 @@ if ('serviceWorker' in navigator) { }); } +// Reload once if a lazy-loaded chunk is missing (stale deployment) +window.addEventListener("vite:preloadError", () => { + if (!sessionStorage.getItem("chunk-reload-attempted")) { + sessionStorage.setItem("chunk-reload-attempted", "1"); + window.location.reload(); + } +}); +// Clear the reload flag after a successful load so future deploys can still trigger a reload +window.addEventListener("load", () => sessionStorage.removeItem("chunk-reload-attempted")); + const mountApp = () => { const rootContainer = document.getElementById('root');