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

Fix service worker gatherer by waiting for active state #1864

Merged
merged 4 commits into from
Apr 26, 2017

Conversation

wardpeet
Copy link
Collaborator

Fixes #1815 where we don't wait until the service worker is active.
Happens mostly on slow connections

not sure if I should mock and create a test for this?

@paulirish
Copy link
Member

Do we have a fairly solid repro for the bug?

I'm trying it with heavier throttling on both caltrainschedule and fuzecaresystem and i can't repro the bug.

@wardpeet
Copy link
Collaborator Author

wardpeet commented Mar 17, 2017

In my test case you can see the issue at end. First it's installing and the audit goes right through it, now it waits for activated.

I throttled my connection with charles and could reproduce it quite often. One time I didn't have a service worker, the other time I did.

@wardpeet
Copy link
Collaborator Author

@paulirish here is a url that I could reproduce it with
https://fuzecaresystem.com/ see #1815 for more info

@wardpeet
Copy link
Collaborator Author

Referencing #1815

@stramel
Copy link
Contributor

stramel commented Apr 15, 2017

Can we get this merged in soon?

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This does fix the repro timing issues. Couple of small suggestions on naming to make the code easier to follow. The SW lifecycle still remains mysterious to me :)

const versionUpdatedListener = data => {
// find a service worker with runningStatus that looks like active
// on slow connections the serviceworker might still be installing
const nonRedundantServiceWorkers = data.versions.filter(sw => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest nonRedundantServiceWorkers -> activateCandidates

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update

return sw.status === 'activated';
});

const hasActiveServiceWorker = nonRedundantServiceWorkers.length && activeServiceWorker;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this boolean? Isn't activeServiceWorker enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when reading the code over again it seems like you are right

return sw.status === 'activated';
});

const hasActiveServiceWorker = activeServiceWorker;
Copy link
Contributor

@ebidel ebidel Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's remove save the return value of find() as hasActiveServiceWorker.

@stramel
Copy link
Contributor

stramel commented Apr 25, 2017

LGTM 👍

@ebidel ebidel merged commit 4c34e28 into GoogleChrome:master Apr 26, 2017
paulirish pushed a commit that referenced this pull request Apr 26, 2017
* Wait for active serviceworker

* Fix test cases

* Review fixes

* Review fix
@wardpeet wardpeet deleted the bug/sw-audit branch April 29, 2017 10:18
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

Successfully merging this pull request may close these issues.

4 participants