mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-08-03 09:06:10 -05:00
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:
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user