feat: PWA-Updates erkennen und Nutzer zum Reload auffordern.

Wechselt auf prompt-Modus mit Update-Banner, periodischer SW-Prüfung und no-cache-Headern für Service Worker und index.html.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-29 17:40:23 +02:00
parent b2a28f5782
commit 1f089fdaa7
9 changed files with 236 additions and 3 deletions
+37
View File
@@ -0,0 +1,37 @@
import { useRegisterSW } from 'virtual:pwa-register/react'
const UPDATE_CHECK_INTERVAL_MS = 60 * 60 * 1000
function scheduleUpdateChecks(registration: ServiceWorkerRegistration) {
const checkForUpdate = () => {
registration.update().catch(() => {})
}
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
checkForUpdate()
}
})
window.setInterval(checkForUpdate, UPDATE_CHECK_INTERVAL_MS)
}
export function usePwaUpdate() {
const {
needRefresh: [needRefresh],
updateServiceWorker
} = useRegisterSW({
immediate: true,
onRegisteredSW(_swUrl: string, registration: ServiceWorkerRegistration | undefined) {
if (registration) {
scheduleUpdateChecks(registration)
}
}
})
const updateApp = async () => {
await updateServiceWorker(true)
}
return { needRefresh, updateApp }
}