fix: do not reload the page when the first service worker takes control

On a first visit clients.claim() fired controllerchange and reloaded the page,
throwing the visitor back to the start screen. Only updates reload now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 13:26:30 +03:00
co-authored by Claude Opus 5.5
parent 71ae4ffa9b
commit 53caa0a208
+4 -1
View File
@@ -86,10 +86,13 @@ export function setupPwa(ui) {
);
})
.catch(() => {});
// On a first visit the new worker takes control without any update; reloading then would
// throw the visitor back to the poster or start screen, so only updates reload the page.
const hadController = Boolean(navigator.serviceWorker.controller);
navigator.serviceWorker.addEventListener(
'controllerchange',
() => {
if (reloading) return;
if (reloading || !hadController) return;
reloading = true;
location.reload();
},