Re: [w3c/ServiceWorker] Ensure the addRoutes() to be called within the install event (PR #1744)

> I have some questions:
> 
> 1. Should addRoutes be callable only synchronously within the event handler or while the event is active (aka while the service worker is installing)?

Do you mean that the while the service worker is installing is that the [state](https://w3c.github.io/ServiceWorker/#dfn-state) is "installing"?
Considering the [install](https://w3c.github.io/ServiceWorker/#installation-algorithm) algorithm, the state sounds somewhat large.

Will you help me to understand corner cases that bring difference between two?

> 2. Should addRoute execution delay installation of the service worker?

It should be.  Or, there might be ambiguity on how the subsequent navigation will be handled.
With the rules or without the rules.

> 3. Should addRoutes promise rejection trigger automatic failure of the service worker or should it be let to the website?

Current Chromium implementation allows `addRoutes()` to fail, and it does not bring ServiceWorker failure.  Note that we allow `addRoutes()` to be called multiple times.

The thought behinds are:

1. unsupported condition or source may return promise rejection, and it can be a way for a web developer to understand a supported SW static routing features for each browsers. (https://github.com/WICG/service-worker-static-routing-api/issues/28)
2. avoid allowing a broken third party library to break the site using ServiceWorker completely.

> My preference so far:
> 
> 1. Allow calling addRoutes while the event is active.

As written above, let me ask details.

> 2. Have addRoute execution delay installation of the service worker.
> 3. Leave failure of the installation up to the website.

I think we agree on both 2. and 3.

> Based on this, I would tend to keep the current API signature as is, `addRoutes(RouterRule or sequence)`.

Sure.  I will work on that tomorrow.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/pull/1744#issuecomment-2606829444
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/pull/1744/c2606829444@github.com>

Received on Wednesday, 22 January 2025 10:18:08 UTC