Try to force refresh if old service worker is used (#21561)

* Try to force refresh if old service worker is used

* Update register-service-worker.ts
This commit is contained in:
Bram Kragten 2024-08-02 15:32:21 +02:00 committed by GitHub
parent a9310fdde0
commit 33931b29a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,13 @@ export const registerServiceWorker = async (
return;
}
if (reg?.active?.scriptURL.includes("service_worker.js")) {
// We are running an old version of the service worker. Force reload.
await reg.unregister();
// @ts-ignore Firefox supports force reload
location.reload(true);
}
reg.addEventListener("updatefound", () => {
const installingWorker = reg.installing;