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

skipWaiting in message handler doesn't work #2525

Closed
zdila opened this issue Jun 1, 2020 · 1 comment · Fixed by #2547
Closed

skipWaiting in message handler doesn't work #2525

zdila opened this issue Jun 1, 2020 · 1 comment · Fixed by #2547
Assignees
Labels
Breaking Change Denotes a "major" semver change. Developer Experience Related to ease of use for developers. workbox-core
Milestone

Comments

@zdila
Copy link

zdila commented Jun 1, 2020

Library Affected:
workbox-core

Browser & Platform:
"all browsers"

Issue or Feature Request Description:

Calling skipWaiting() in message event handler does nothing. Instead calling self.skipWaiting() works. Tested in latest stable Chrome and Firefox.

Application uses webpack an InjectManifest plugin.

import { skipWaiting } from 'workbox-core';

addEventListener('message', (event) => {
  if (event.data && event.data.type === 'SKIP_WAITING') {
   // skipWaiting(); // does nothing
    self.skipWaiting(); // works
  }
});

// ...
@jeffposnick
Copy link
Contributor

jeffposnick commented Jun 19, 2020

The skipWaiting function in workbox-core wraps the call to self.skipWaiting() inside of an install event handler:

function skipWaiting() {
// We need to explicitly call `self.skipWaiting()` here because we're
// shadowing `skipWaiting` with this local function.
self.addEventListener('install', () => self.skipWaiting());
}

I have wondered how much value is added by workbox-core's skipWaiting(), since it should be "safe" to call self.skipWaiting() outside of an install handler. (The same isn't the case for self.clients.claim(), which throws an exception when called unless there's an active service worker.)

I'm in favor making a change in v6 that just makes workbox-core's skipWaiting() call self.skipWaiting() directly, without the install event wrapper, and logs a message in dev mode telling folks to migrate to using self.skipWaiting() directly. And then maybe we'll remove skipWaiting() in v7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Denotes a "major" semver change. Developer Experience Related to ease of use for developers. workbox-core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants