From ba1ddd4489198763f45acb7168bdc7d3188e296d Mon Sep 17 00:00:00 2001 From: Frederic Cabassut Date: Thu, 12 Mar 2026 21:00:50 +0100 Subject: [PATCH] fix: restrict SW API caching to GET requests to avoid intercepting mutations Workbox route matching intercepts all HTTP methods, which caused PUT/POST requests (e.g. preferences updates) to be handled by the SW strategy handler instead of passing through directly. Restrict API and attachment cache rules to GET-only using function-based urlPattern. Co-Authored-By: Claude Opus 4.6 --- vite.config.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index d311771..4ecbe36 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -52,7 +52,9 @@ export default defineConfig({ } }, { - urlPattern: /\/api\/notes\/.*\/attachments\?attachmentId=/, + urlPattern: ({ request, url }) => + request.method === 'GET' && + /\/api\/notes\/.*\/attachments\?attachmentId=/.test(url.href), handler: 'CacheFirst', options: { cacheName: 'attachment-cache', @@ -60,7 +62,8 @@ export default defineConfig({ } }, { - urlPattern: /^https?:\/\/.*\/api\//, + urlPattern: ({ request, url }) => + request.method === 'GET' && /\/api\//.test(url.pathname), handler: 'NetworkFirst', options: { cacheName: 'api-cache',