From 7a0c57a79c5ebd7c06f5a6f931eb7c01ac24cbe1 Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Thu, 11 Jun 2026 10:36:20 +0300 Subject: [PATCH] feat(frontend): finish PWA reset reload and pre-cache the HTML shell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The service worker and web manifest were already in place; close the remaining gaps against the PWA spec: - pwa.ts: resetPwa() cleared caches and unregistered the service worker but never reloaded, despite its docstring. Add the hard reload so the page re-fetches everything from the network after a clear. - service-worker.ts: pre-cache the SPA entry HTML ('/') alongside build/files so the shell — and the offline navigation fallback — works from the very first visit, not just after a navigation has been seen by the runtime cache. - settings: resetPwa now reloads, so the post-clear success toast (which told the user to reload manually) is unreachable and misleading. Drop the dead pwaSuccess state and toast; keep the disabled "Clearing…" button state. Co-Authored-By: Claude Opus 4.8 --- frontend/src/lib/utils/pwa.ts | 3 +++ frontend/src/routes/settings/+page.svelte | 12 ++++-------- frontend/src/service-worker.ts | 7 +++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/src/lib/utils/pwa.ts b/frontend/src/lib/utils/pwa.ts index 951ca05..fcedfda 100644 --- a/frontend/src/lib/utils/pwa.ts +++ b/frontend/src/lib/utils/pwa.ts @@ -11,4 +11,7 @@ export async function resetPwa(): Promise { const keys = await caches.keys(); await Promise.all(keys.map((k) => caches.delete(k))); } + // Hard reload so the page (and a fresh service worker, if still installed) + // re-fetches everything from the network instead of the now-cleared cache. + location.reload(); } \ No newline at end of file diff --git a/frontend/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte index 9bedbe0..243a319 100644 --- a/frontend/src/routes/settings/+page.svelte +++ b/frontend/src/routes/settings/+page.svelte @@ -85,16 +85,15 @@ }); // ---- PWA reset ---- + // doPwaReset() clears the caches/SW and then hard-reloads the page, so there's + // no post-success state to surface here — just keep the button disabled while it + // runs until the reload takes over. let pwaResetting = $state(false); - let pwaSuccess = $state(false); async function resetPwa() { pwaResetting = true; - pwaSuccess = false; try { await doPwaReset(); - pwaSuccess = true; - setTimeout(() => (pwaSuccess = false), 3000); } finally { pwaResetting = false; } @@ -226,10 +225,7 @@

App cache

-

Clear service worker and cached assets. Useful if the app feels stale after an update.

- {#if pwaSuccess} -

Cache cleared. Reload the page to fetch fresh assets.

- {/if} +

Clear service worker and cached assets, then reload. Useful if the app feels stale after an update.