w3c / w3c/ServiceWorker

ready promise is kind of weird with overlapping scopes

Open
#1,278 26 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

Consider this situation:

// Window foo.com/bar/baz/index.html
await navigator.serviceWorker.register('sw.js', { scope: '/bar' });

navigator.serviceWorker.ready.then(swr => {
  console.log(swr.scope);
});

await navigator.serviceWorker.register('sw.js', { scope: '/bar/baz' });

navigator.serviceWorker.ready.then(swr => {
  console.log(swr.scope);
});

The first ready promise gets the '/bar' scope registration and waits for it to activate. This is step 4.3 of here:

https://w3c.github.io/ServiceWorker/#navigator-service-worker-ready

Assuming that the '/bar' worker does not activate immediately, we might get the '/bar/baz' worker registration started.

What should the second .ready promise access do? The promise is not settled yet, but the previous access is in a parallel bit of algorithm waiting for '/bar' to activate. Should the second access block on that somehow or start waiting on '/bar/baz' instead?

Kind of a corner case, but its a bit weird.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Navigator service worker ready algorithm at https://w3c.github.io/ServiceWorker/#navigator-service-worker-ready, especially step 4.3. Trace the overlapping /bar and /bar/baz registration scenario described in the issue. Done means the specification clearly defines which registration each later ready access waits for and how concurrent accesses behave.

Written by the indexing model from the issue text.

Assessment

Domain
api, web-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.