Skip to content

fix(web): wire real PWA auto-update instead of the plugin's no-op default#86

Merged
cipher813 merged 1 commit into
mainfrom
fix/pwa-auto-update-reload
Jul 8, 2026
Merged

fix(web): wire real PWA auto-update instead of the plugin's no-op default#86
cipher813 merged 1 commit into
mainfrom
fix/pwa-auto-update-reload

Conversation

@cipher813

Copy link
Copy Markdown
Contributor

Summary

vite.config.ts declared registerType: 'autoUpdate', but nothing in the app ever imported virtual:pwa-register — so vite-plugin-pwa fell back to injecting a bare navigator.serviceWorker.register('/sw.js') script with zero update-detection or reload logic. The generated SW already calls self.skipWaiting() + clientsClaim(), so a new deploy's SW silently takes control of open tabs — but nothing ever tells those tabs to reload, so they keep running the old JS bundle indefinitely until every tab is fully closed.

Found this diagnosing "PR#85 merged but I still see the old behavior live" — verified the server was serving the correct, freshly-built bundle (hash matched a from-source rebuild of the merge commit), so the gap was entirely client-side SW update propagation, not caching/CDN/deploy lag.

Fix

Register the SW via the official React hook (useRegisterSW from virtual:pwa-register/react, called in App.tsx) so autoUpdate mode's real behavior — silent auto-reload once the new SW activates — actually runs. injectRegister: null stops the plugin from also injecting its redundant no-op script.

Test plan

  • npx tsc -b — clean
  • npm run builddist/index.html no longer references a registerSW.js script; virtual:pwa-register/react resolves and is bundled (workbox-window chunk present)
  • npx vitest run — 144/144 passing
  • npx oxlint — no new warnings
  • Live verify after merge: confirm an already-open tab picks up the NEXT deploy without a manual reload

…ault

vite.config.ts declared `registerType: 'autoUpdate'`, but nothing in
the app ever imported `virtual:pwa-register` — so vite-plugin-pwa fell
back to injecting a bare `navigator.serviceWorker.register('/sw.js')`
script with zero update-detection or reload logic. Combined with the
generated SW's skipWaiting()+clientsClaim() (already on), a new
deploy's service worker silently took control of open tabs without
ever telling them to reload — so the app kept running the OLD JS
bundle indefinitely until every tab was fully closed. Confirmed live:
PR#85 was merged, deployed, and served correctly by the origin (bundle
hash matched a from-source rebuild of the merge commit), but a
same-session open tab still showed neither the fix nor the new delete
button, because this registration gap has nothing to do with server
caching or CDN — it's entirely client-side.

Fix: register the service worker ourselves via the official React hook
(`useRegisterSW` from `virtual:pwa-register/react`, in App.tsx) so the
`autoUpdate` mode's real behavior — auto-reload once the new SW
activates — actually runs. `injectRegister: null` stops the plugin
from also injecting its redundant no-op script.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cipher813 cipher813 merged commit 3f78c51 into main Jul 8, 2026
3 checks passed
@cipher813 cipher813 deleted the fix/pwa-auto-update-reload branch July 8, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant