From 69aea1a90907679ae4fd2873fdd94959be592005 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 24 Apr 2025 12:38:30 +0500 Subject: [PATCH] web: improve update installation --- apps/web/src/utils/updater.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/web/src/utils/updater.ts b/apps/web/src/utils/updater.ts index 909060145..b0052defa 100644 --- a/apps/web/src/utils/updater.ts +++ b/apps/web/src/utils/updater.ts @@ -73,13 +73,19 @@ export async function installUpdate() { else { const registrations = (await navigator.serviceWorker?.getRegistrations()) || []; - let reload = false; for (const registration of registrations) { if (registration.waiting) { + registration.waiting.addEventListener("statechange", () => { + const worker = + registration.active || + registration.waiting || + registration.installing; + if (worker?.state === "activated") { + window.location.reload(); + } + }); registration.waiting.postMessage({ type: "SKIP_WAITING" }); - reload = true; } } - if (reload) window.location.reload(); } }