From b7c121a08437608092bd7823963ab75b2c3c267c Mon Sep 17 00:00:00 2001 From: Marcio Bevervanso Date: Tue, 17 Feb 2026 20:52:46 -0300 Subject: [PATCH] fix(pwa): Enable NetworkOnly Service Worker to allow installation without lag --- vite.config.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 33ad326..135a481 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,8 +14,7 @@ export default defineConfig(({ mode }) => { react(), VitePWA({ registerType: 'autoUpdate', - injectRegister: null, // Disable automatic SW injection to fix lag - selfDestroying: true, // Force unregister existing SW + injectRegister: 'auto', // Re-enable SW for installation criteria includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'masked-icon.svg'], manifest: { name: 'FoodSnap.ai', @@ -45,6 +44,11 @@ export default defineConfig(({ mode }) => { ] }, workbox: { + // NetworkOnly strategy to prevent caching issues/lag but allow installation + runtimeCaching: [{ + urlPattern: ({ request }) => request.destination === 'document' || request.destination === 'script' || request.destination === 'style' || request.destination === 'image', + handler: 'NetworkOnly', + }], cleanupOutdatedCaches: true, skipWaiting: true, clientsClaim: true,