Re: [ServiceWorker] Install algorithm step 14 should clear waiting worker before updating state to redundant (#851)

Well, let me try to clarify what we want to make clear:

> It seems the statechange event triggered by 14.2 Update State might see the redundant worker still set as registration.waiting. Most other instances of Update State change the registration attribute first.

The order of Invoking Update State and changing the registration's attribute varies case by case depending on which `ServiceWorker` objects in the client contexts should be notified the change event.

Note that `ServiceWorker` object captured in a client context (either main thread or worker) has an associated service worker determined at the time of the execution of the getters (`.installing/.waiting/.active/.controller`). And those associated service workers' state change during the installation process. What Update State does is finding all the `ServiceWorker` objects associated with the given service worker and queue a task to fire the statechange events to those client contexts. For example, the Install step 17 invokes Update State with registrations.waiting after setting its value to registration.installing in the step 15. Then from the script surface, all the `ServiceWorker` objects captured by `registration.installing` before these Install step reached will be getting dispatched the `statechange` event, its state having changed to `redundant`.

In the same way, what the Install step 14 does in the OP is to find all the `ServiceWorker` objects associated with the current registration.waiting (before nullified) and queue a task to those clients to notify now it's redundant.

> As a side note, should the statechange event see the new service worker in registration.waiting or a null .waiting?

I think registration.waiting inside the event listener of the statechange event should be a new service worker (the installing worker promoted to waiting worker.) So then we may need more precise description that the Install step 15 should be run before the event listener of the statechange event in the main thread is invoked?

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/851#issuecomment-199706824

Received on Tuesday, 22 March 2016 08:59:23 UTC