From 62cb67aa8ea50bd09f148c0ec4069afdcd8489f0 Mon Sep 17 00:00:00 2001 From: cialloo Date: Mon, 27 Oct 2025 23:06:51 +0800 Subject: [PATCH] feat: add service worker cleanup to remove legacy registrations on startup --- src/main.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.tsx b/src/main.tsx index f4ca2de..1ceb3dc 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -19,6 +19,22 @@ import AuthCallback from './pages/AuthCallback.tsx' import BlogPost from './pages/BlogPost.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(