The shell-asset fetch handler intends to use stale-while-revalidate behavior: when an asset is already cached it returns the cached response immediately and starts a network refresh that writes the fresh response back with cache.put().
However, the refresh promise is not passed to event.waitUntil(). When a cache hit exists, respondWith() resolves as soon as the cached Response is returned, so the fetch event can finish and the service worker is allowed to be terminated before the background fetch(...).then(cache.put(...)) completes. That makes the refresh best-effort rather than guaranteed, undermining the existing stale-asset protection.
Expected behavior: when a cached shell asset is returned, keep the revalidation promise alive with event.waitUntil(fresh) and still return the cached response immediately. On a cache miss, continue returning the network promise directly.
I can submit a small regression test plus fix. Prepared with AI assistance and reviewed against the current web/public/sw.js and test/sw.test.ts.
The shell-asset fetch handler intends to use stale-while-revalidate behavior: when an asset is already cached it returns the cached response immediately and starts a network refresh that writes the fresh response back with
cache.put().However, the refresh promise is not passed to
event.waitUntil(). When a cache hit exists,respondWith()resolves as soon as the cachedResponseis returned, so the fetch event can finish and the service worker is allowed to be terminated before the backgroundfetch(...).then(cache.put(...))completes. That makes the refresh best-effort rather than guaranteed, undermining the existing stale-asset protection.Expected behavior: when a cached shell asset is returned, keep the revalidation promise alive with
event.waitUntil(fresh)and still return the cached response immediately. On a cache miss, continue returning the network promise directly.I can submit a small regression test plus fix. Prepared with AI assistance and reviewed against the current
web/public/sw.jsandtest/sw.test.ts.