fix: auto-reload on stale chunk load failure (vite:preloadError)
CI / Build & Quality Checks (push) Failing after 5m28s

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.
This commit is contained in:
Lotus Bot
2026-05-22 02:31:54 -04:00
parent eb2e2670d9
commit 88658e0c3b
+10
View File
@@ -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');