From 06a4aa6048460eb64b88820d42ac50303df4edde Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:31:26 +0700 Subject: [PATCH 1/3] fix(pwa): recover even when service worker registration lookup rejects --- public/offline.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/offline.html b/public/offline.html index 7b43d2ce..82d5bae0 100644 --- a/public/offline.html +++ b/public/offline.html @@ -93,8 +93,16 @@

You're offline

try { // The active worker gives us the correct deployment scope for deep // links and /pr-preview/pr-N/ paths, not just the production root. - const registration = await navigator.serviceWorker?.getRegistration?.(); - const scope = registration?.scope || new URL('/', window.location.origin).href; + let registration; + try { + registration = await navigator.serviceWorker?.getRegistration?.(); + } catch { + // A blocked or unavailable service-worker API must not prevent + // recovery when the website is already reachable again. + } + const previewPath = window.location.pathname.match(/^\\/pr-preview\\/pr-[1-9]\\d*\\//)?.[0]; + const fallbackScope = new URL(previewPath || '/', window.location.origin).href; + const scope = registration?.scope || fallbackScope; // A non-navigation request bypasses our navigation-only offline // fallback. Require a real, valid manifest before reloading. const probeUrl = new URL('brand/site.webmanifest', scope); From 2491334f50cb676330a6c485a8bd7b39e5989251 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:31:53 +0700 Subject: [PATCH 2/3] fix(pwa): correct preview path regex for fallback scope --- public/offline.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/offline.html b/public/offline.html index 82d5bae0..78fee9ea 100644 --- a/public/offline.html +++ b/public/offline.html @@ -100,7 +100,7 @@

You're offline

// A blocked or unavailable service-worker API must not prevent // recovery when the website is already reachable again. } - const previewPath = window.location.pathname.match(/^\\/pr-preview\\/pr-[1-9]\\d*\\//)?.[0]; + const previewPath = window.location.pathname.match(/^\/pr-preview\/pr-[1-9]\d*\//)?.[0]; const fallbackScope = new URL(previewPath || '/', window.location.origin).href; const scope = registration?.scope || fallbackScope; // A non-navigation request bypasses our navigation-only offline From 77035ba01bac75c6e19c5526e3f738e019cb9077 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:32:20 +0700 Subject: [PATCH 3/3] test(pwa): exercise recovery when service worker lookup fails --- tests/pwa-reconnect.test.mjs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/pwa-reconnect.test.mjs b/tests/pwa-reconnect.test.mjs index 05e184b0..ef25d466 100644 --- a/tests/pwa-reconnect.test.mjs +++ b/tests/pwa-reconnect.test.mjs @@ -5,7 +5,7 @@ import { runInNewContext } from 'node:vm'; const read = path => readFile(new URL('../' + path, import.meta.url), 'utf8'); -async function offlinePageHarness({ reachable = false, hidden = false, validManifest = true } = {}) { +async function offlinePageHarness({ reachable = false, hidden = false, validManifest = true, serviceWorkerFails = false } = {}) { const html = await read('public/offline.html'); const script = html.match(/