From 4b2007e97cada08029a508264d09522b6b907ae7 Mon Sep 17 00:00:00 2001 From: Till JS Date: Tue, 14 Apr 2026 14:05:49 +0200 Subject: [PATCH] fix(pwa): wire up manifest link + SW registration so install prompt works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PWA was configured end-to-end in vite.config.ts and built the manifest + service worker correctly, but neither was ever loaded by the browser — no in the HTML and no script registering the generated registerSW.js. Chrome therefore never fired beforeinstallprompt, no install icon appeared in the URL bar, and the hand-rolled PwaUpdatePrompt hung on navigator.serviceWorker.ready because no SW had been registered. Changes: - Render pwaInfo.webManifest.linkTag into in the root layout so Chrome finds the hashed manifest. - Replace the hand-rolled SW-update logic in PwaUpdatePrompt with useRegisterSW() from virtual:pwa-register/svelte — it registers the worker (immediate: true) and exposes reactive needRefresh + updateServiceWorker stores that match registerType: 'prompt'. - Add triple-slash refs to vite-plugin-pwa/info and /svelte in app.d.ts for the virtual module types. - Set manifest.id = startUrl in @mana/shared-pwa so Chrome doesn't warn and keeps the install identity stable across start_url edits. - Keep devEnabled: false and expand the comment: the 2026-04-08 dreams mic-button bug and the /offline navigateFallback both misbehave when Workbox precache doesn't run under vite dev. Test the install flow via `pnpm build && pnpm preview` instead. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/mana/apps/web/src/app.d.ts | 7 ++ .../src/lib/components/PwaUpdatePrompt.svelte | 64 +++++-------------- apps/mana/apps/web/src/routes/+layout.svelte | 11 ++++ apps/mana/apps/web/vite.config.ts | 17 ++--- packages/shared-pwa/src/config.ts | 4 ++ packages/shared-pwa/src/types.ts | 7 ++ 6 files changed, 55 insertions(+), 55 deletions(-) diff --git a/apps/mana/apps/web/src/app.d.ts b/apps/mana/apps/web/src/app.d.ts index b6f0df82a..deac78a15 100644 --- a/apps/mana/apps/web/src/app.d.ts +++ b/apps/mana/apps/web/src/app.d.ts @@ -4,6 +4,13 @@ * Authentication is handled entirely by Mana Core Auth (@mana/shared-auth). * No Supabase is needed - all data comes from mana-auth APIs. */ + +// Virtual modules provided by vite-plugin-pwa (wrapped by @vite-pwa/sveltekit): +// - virtual:pwa-info → pwaInfo.webManifest.linkTag for +// - virtual:pwa-register/svelte → useRegisterSW() Svelte-store hook +/// +/// + declare global { const __BUILD_HASH__: string; const __BUILD_TIME__: string; diff --git a/apps/mana/apps/web/src/lib/components/PwaUpdatePrompt.svelte b/apps/mana/apps/web/src/lib/components/PwaUpdatePrompt.svelte index 72e0c2e87..1060a153a 100644 --- a/apps/mana/apps/web/src/lib/components/PwaUpdatePrompt.svelte +++ b/apps/mana/apps/web/src/lib/components/PwaUpdatePrompt.svelte @@ -1,64 +1,34 @@ -{#if showPrompt} +{#if $needRefresh}