feat: add service worker cleanup to remove legacy registrations on startup
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 23s

This commit is contained in:
2025-10-27 23:06:51 +08:00
parent e241f789ed
commit 62cb67aa8e

View File

@@ -19,6 +19,22 @@ import AuthCallback from './pages/AuthCallback.tsx'
import BlogPost from './pages/BlogPost.tsx' import BlogPost from './pages/BlogPost.tsx'
import EditPost from './pages/EditPost.tsx' import EditPost from './pages/EditPost.tsx'
// Ensure any legacy service workers from previous deployments are removed.
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.getRegistrations()
.then((registrations) => {
registrations.forEach((registration) => {
registration.unregister().catch(() => {
// Swallow errors since stale service workers are non-critical.
})
})
})
.catch(() => {
// Ignore lookup errors; the app functions without service workers.
})
}
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<ThemeProvider> <ThemeProvider>