From 53caa0a2080782a1013b1386653c9e002be5fa93 Mon Sep 17 00:00:00 2001 From: "hamed@B" Date: Sat, 31 Oct 2026 13:26:30 +0300 Subject: [PATCH] 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 --- src/game/device/pwa.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/game/device/pwa.js b/src/game/device/pwa.js index 7371de1..f4056d6 100644 --- a/src/game/device/pwa.js +++ b/src/game/device/pwa.js @@ -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(); },