From 1a3556be2ca3478845741454541401ee326d8540 Mon Sep 17 00:00:00 2001 From: HomeOS Bootstrap Date: Sat, 18 Jul 2026 01:27:41 +0200 Subject: [PATCH] fix(pwa): await service-worker cache write (R15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- public/sw.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/sw.js b/public/sw.js index edc756a..6e8f608 100644 --- a/public/sw.js +++ b/public/sw.js @@ -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; }