fix(sw): move skipWaiting inside install promise, use clients.claim in activate

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
posimai 2026-04-17 13:11:41 +09:00
parent 2319982445
commit 6c3d92f5b0
1 changed files with 3 additions and 4 deletions

7
sw.js
View File

@ -4,18 +4,17 @@ const ORIGIN = self.location.origin;
self.addEventListener('install', e => {
e.waitUntil(
caches.open(CACHE).then(c => c.addAll(ASSETS))
caches.open(CACHE).then(c => c.addAll(ASSETS)).then(() => self.skipWaiting())
);
self.skipWaiting();
});
self.addEventListener('activate', e => {
e.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
).catch(err => console.warn('[SW] activate error', err))
).then(() => self.clients.claim())
.catch(err => console.warn('[SW] activate error', err))
);
self.clients.claim();
});
self.addEventListener('fetch', e => {