fix: update PWA workers without reloading pages
Quality / quality (ubuntu-latest) (push) Failing after 12m52s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
2026-08-03 00:54:29 +05:30
parent 379f80cbd0
commit b61020babd
2 changed files with 7 additions and 13 deletions
+5 -11
View File
@@ -312,18 +312,12 @@ export function renderPwaClient(version = "2") {
swUrl = window.trustedTypes.createPolicy("wrnexus-pwa", { createScriptURL: function(value) { return value; } }).createScriptURL(swUrl);
} catch (_) {}
}
var reloading = false;
navigator.serviceWorker.addEventListener("controllerchange", function () {
var key = "wrnexus-pwa-controller-" + swVersion;
if (reloading || sessionStorage.getItem(key)) return;
reloading = true;
sessionStorage.setItem(key, "1");
location.reload();
});
addEventListener("load", function () {
navigator.serviceWorker.register(swUrl, { updateViaCache: "none" }).then(function (registration) {
return registration.update();
}).catch(function () {});
var register = function () {
navigator.serviceWorker.register(swUrl, { updateViaCache: "none" }).catch(function () {});
};
if ("requestIdleCallback" in window) window.requestIdleCallback(register, { timeout: 2000 });
else setTimeout(register, 0);
});
}`;
}