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

@youennf commented on this pull request.



> -        1. Set |serviceWorker|'s [=service worker/list of router rules=] to |routerRules|.
-        1. Return [=a promise resolved with=] undefined.
+            1. If |rule|["{{RouterRule/source}}"] is "{{RouterSourceEnum/fetch-event}}" and |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] {{ServiceWorkerGlobalScope/fetch!!event}}, return [=a promise rejected with=] a {{TypeError}}.
+        1. Let |lifetimePromise| be a new [=promise=].
+        1. [=ExtendableEvent/Add lifetime promise=] |lifetimePromise| to |event|.
+
+            Note: {{InstallEvent/addRoutes(rules)|event.addRoutes(rules)}} extends the lifetime of the event by default as if {{ExtendableEvent/waitUntil()|event.waitUntil(promise)}} is called.
+
+        1. Let |promise| be a new [=promise=].
+        1. [=In parallel=]:
+            1. Upon [=upon fulfillment|fulfillment=] or [=upon rejection|rejection=] of |promise|, resolve |lifetimePromise| with undefined.
+
+                Note: this step is for making |lifetimePromise| always fullfilled to avoid the install event failure.
+
+        1. Let |serviceWorkerEventLoop| be the [=current global object=]'s [=event loop=].
+        1. [=Queue a task=] to run the following steps on |serviceWorkerEventLoop| using the [=DOM manipulation task source=]:

Right, we definitely want to preserve determinism.
The solution is probably to use a parallel queue, like https://w3c.github.io/webcodecs/#codec-work-queue, and use it.

That said, this is an existing issue in the service worker spec, see cache algorithms for instance.
I would go with a comment stating that it is expected that the order of the rules is preserved.

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

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

Received on Monday, 27 January 2025 11:36:52 UTC