fix(frontend): don't reload page on first service worker install

clientsClaim() fires controllerchange when the freshly installed service
worker takes control of the page on first visit, which reloaded the app
and wiped unsaved state such as login form input. Only reload after the
user explicitly confirmed an update.

Fixes #3251
This commit is contained in:
kolaente
2026-07-22 08:48:24 +00:00
committed by kolaente
parent 658d459f9b
commit 7ccfd4a111
@@ -30,8 +30,11 @@ document.addEventListener('swUpdated', showRefreshUI, {once: true})
navigator?.serviceWorker?.addEventListener(
'controllerchange', () => {
if (refreshing.value) return
refreshing.value = true
// clientsClaim() also fires this on first install — only reload after
// the user opted into an update, or unsaved state (e.g. login form
// input) gets wiped.
if (!refreshing.value) return
refreshing.value = false
window.location.reload()
},
)
@@ -48,6 +51,7 @@ function refreshApp() {
if (!registration.value || !registration.value.waiting) {
return
}
refreshing.value = true
// Notify the service worker to actually do the update
registration.value.waiting.postMessage('skipWaiting')
}