feat(web): auto-update the PWA when a new release is deployed
Register the service worker from the app (virtual:pwa-register) instead of the injected script, so an installed PWA that stays open also checks for a new worker every 30 minutes, when it returns to the foreground and when the connection comes back. The new worker skips waiting, claims every tab and the page reloads into it, deferring the reload until the app is backgrounded if the user is typing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,10 +15,11 @@ export default defineConfig({
|
||||
react(),
|
||||
tailwindcss(),
|
||||
VitePWA({
|
||||
// `autoUpdate` pre-caches the app shell and swaps in new releases on the
|
||||
// next navigation. Registration is injected into `index.html` at build
|
||||
// time, so no `virtual:pwa-register` import is needed in the app.
|
||||
// `autoUpdate`: a new service worker activates as soon as it is installed
|
||||
// and the page reloads into the new release. Registration (and the
|
||||
// periodic update checks) live in `src/lib/register-sw.ts`.
|
||||
registerType: 'autoUpdate',
|
||||
injectRegister: false,
|
||||
includeAssets: ['favicon.svg', 'apple-touch-icon.png'],
|
||||
manifest: {
|
||||
name: 'Superlist — Listas de compras compartidas',
|
||||
@@ -48,6 +49,11 @@ export default defineConfig({
|
||||
// SPA fallback so deep links work offline, but never swallow API calls.
|
||||
navigateFallback: 'index.html',
|
||||
navigateFallbackDenylist: [/^\/api\//],
|
||||
// Drop caches left behind by previous releases once the new one activates.
|
||||
cleanupOutdatedCaches: true,
|
||||
// Take control of every open tab as soon as the new worker activates.
|
||||
clientsClaim: true,
|
||||
skipWaiting: true,
|
||||
},
|
||||
devOptions: {
|
||||
// The service worker is only built for `vite build`; verify with `preview`.
|
||||
|
||||
Reference in New Issue
Block a user