fix(pwa): await service-worker cache write (R15)

Codex R15 (P2): cacheFirst() fired cache.put() without awaiting, so the worker
could be terminated before the write persisted, losing the asset for offline
use. Await it — respondWith() keeps the worker alive for the returned promise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/phase-1-bootstrap
HomeOS Bootstrap 2026-07-18 01:27:41 +02:00
parent 8aa3257fa2
commit 1a3556be2c
1 changed files with 3 additions and 1 deletions

View File

@ -59,7 +59,9 @@ async function cacheFirst(req) {
const hit = await cache.match(req);
if (hit) return hit;
const res = await fetch(req);
if (res && res.ok) cache.put(req, res.clone());
// Await the write: respondWith() keeps the worker alive for this promise, so the asset is
// actually persisted before the worker can be terminated (otherwise offline use loses it).
if (res && res.ok) await cache.put(req, res.clone());
return res;
}