WICG / service-worker-static-routing-api

A repository for the ServiceWorker static routing API.
Other
26 stars 6 forks source link

Need to consider "no fetch handler" situation in the spec update process #14

Closed azaika closed 9 months ago

azaika commented 11 months ago

After the static routing API is introduced, service worker registrations can be like the following:

self.addEventListener('install', async e => {
  await e.registerRouter([
    {
      condition: { requestMethod: 'GET' },
      source: 'cache'
    }
  ]);
  self.skipWaiting();
});

// no fetch handlers

This code expects all GET request to refer the service worker cache and does not register any fetch handlers.

However, it seems that the current ServiceWorker spec [1] does not consider the situation where no fetch handlers are registered. For example, the "Handle Fetch" algorithm of the spec [2] stipulates that:

  1. If the result of running the Should Skip Event algorithm with "fetch" and activeWorker is true, then:

    1. If shouldSoftUpdate is true, then in parallel run the Soft Update algorithm with registration.
    2. Return null.

This means that service workers do not work if web developers do not write their own fetch handlers, and at least, the "Should Skip Event" algorithm should be updated.

[1] https://w3c.github.io/ServiceWorker/ [2] https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm

yoshisatoyanagisawa commented 11 months ago

Thanks for filing the issue. That is an area that the explainer has not considered yet. When I wrote https://github.com/WICG/service-worker-static-routing-api#how-does-it-work-with-empty-fetch-listeners, I supposed source would be network, and thought no fetch handlers or an empty fetch handlers are ignorable. However, considering cache, we cannot.

yoshisatoyanagisawa commented 9 months ago

I think https://github.com/yoshisatoyanagisawa/ServiceWorker/pull/2 covers the way to deal with the no fetch handler case.

Chromium implementation must be fixed to deal with the cases. It is tracked in crbug.com/1511459.