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');