Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should register() trigger byte-for-byte checking when WorkerType is updated? #1408

Closed
makotoshimazu opened this issue May 20, 2019 · 3 comments
Assignees

Comments

@makotoshimazu
Copy link

// (1) Register sw.js as classic script.
await navigator.serviceWorker.register('sw.js', {type: 'classic'});
// (2) Register sw.js as module script with the same script.
await navigator.serviceWorker.register('sw.js', {type: 'module'});

Should (2) install a new ServiceWorker and invoke install/activate event?

@mfalken
Copy link
Member

mfalken commented May 20, 2019

I think I'd expect a new service worker to be installed and the byte-to-byte check skipped as if the URL changed.

See also #1359.

@makotoshimazu
Copy link
Author

Thanks!
The current spec seems to have another edge case where install/activate events are not triggered as follows, and it also can be solved by adding a "skip byte-to-byte checking" flag.

// ==== script in something.html ====
// Register a.js, and it imports b.js too.
await navigator.serviceWorker.register('a.js');
// Register b.js, but b.js is identical to the one we previously put into the script cache map.
await navigator.serviceWorker.register('b.js');

// ==== a.js ====
a = true;
if (typeof b === 'undefined') {
  importScripts('b.js');
}

// ==== b.js ====
b = true;
if (typeof a === 'undefined') {
  importScripts('a.js');
}

For example, does changing [[Register]] like this and refers to the flag in the [[Update]] algorithm make sense?

  1. If registration is not null, then:
    ....
    4. If newestWorker is not null, job's script url doesn't equal to newestWorker's script url or job's worker type doesn't equal to newestWorker's worker type, then:
    1. Set job's skip byte-for-byte comparison to true.

@mfalken mfalken self-assigned this Jun 3, 2019
mfalken added a commit to mfalken/ServiceWorker that referenced this issue Jun 3, 2019
This makes the following changes:
* updateViaCache is a live property. This is covered by the WPT
registration-updateviacache.https.html. However we are missing tests for a
register() that rejects with a new updateViaCache property. The desired
behavior is to only update the property if register() resolves.
* Changing worker type bypasses the byte-for-byte update check. This is covered
by WPT update-registration-with-type.https.html.
* Adds Worker type and updateViaCache to the job equivalence check. This
probably can have a WPT for successive register() calls that vary these
properties don’t get coalesced into a single job.

Addresses w3c#1189, w3c#1408, w3c#1359, and w3c#1358.
mfalken added a commit that referenced this issue Jun 3, 2019
…1411)

This makes the following changes:
* updateViaCache is a live property. This is mostly covered by the WPT
registration-updateviacache.https.html. A test that the updateViaCache
change is only committed if the register() call resolves is added in
web-platform-tests/wpt#17131.
* Changing worker type bypasses the byte-for-byte update check. This is covered
by WPT update-registration-with-type.https.html.
* Adds Worker type and updateViaCache to the job equivalence check. A
test for this is added in web-platform-tests/wpt#17131.

Addresses #1189, #1408, #1359, and #1358.
@mfalken
Copy link
Member

mfalken commented Jun 3, 2019

Addressed in #1411

@mfalken mfalken closed this as completed Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants