Unregister existing service workers (#722)

In case some other app was served on the same domain which registered a service worker, this service worker was incorrectly used and never unregistered
This commit is contained in:
schroda
2024-04-09 23:37:41 +02:00
committed by GitHub
parent 0490851deb
commit 53de29f263

View File

@@ -12,6 +12,18 @@ import { App } from '@/App';
import '@/index.css';
// roboto font
import '@fontsource/roboto';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then((registration) => {
registration.unregister().catch(defaultPromiseErrorHandler('unregister service workers'));
if (caches) {
caches.keys().then(async (names) => {
await Promise.all(names.map((name) => caches.delete(name)));
});
}
});
}
const container = document.getElementById('root');
const root = createRoot(container!);