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:
@@ -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();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user