fix(pwa): Enable NetworkOnly Service Worker to allow installation without lag

This commit is contained in:
Marcio Bevervanso 2026-02-17 20:52:46 -03:00
parent c6769cb884
commit b7c121a084

View file

@ -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,