Skip to content

Service worker background shell refresh can be terminated before cache.put finishes #87

Description

@iliasaberkane6-lab

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions