From 8e8212c580be013fa7b700dbde2b55418c6a6788 Mon Sep 17 00:00:00 2001 From: haorwen Date: Mon, 13 Apr 2026 23:28:46 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=94=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/serviceWorkerRegistration.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/serviceWorkerRegistration.ts b/src/serviceWorkerRegistration.ts index 022294b4..ffba4472 100644 --- a/src/serviceWorkerRegistration.ts +++ b/src/serviceWorkerRegistration.ts @@ -62,6 +62,15 @@ function registerValidSW(swUrl: string, config: Config) { navigator.serviceWorker .register(swUrl) .then((registration) => { + // If a waiting SW already exists (e.g. user previously dismissed the toast), + // re-trigger onUpdate so the toast appears again on refresh. + if (registration.waiting && navigator.serviceWorker.controller) { + if (config && config.onUpdate) { + config.onUpdate(registration); + } + return; + } + registration.onupdatefound = () => { const installingWorker = registration.installing; if (installingWorker == null) { @@ -96,6 +105,10 @@ function registerValidSW(swUrl: string, config: Config) { } }; }; + + // Force an update check on every page load/refresh, + // so new versions are discovered immediately. + registration.update().catch(() => {}); }) .catch((error) => { console.error("Error during service worker registration:", error);