-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Conversation
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. |
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. |
@paulirish here is a url that I could reproduce it with |
Referencing #1815 |
Can we get this merged in soon? |
There was a problem hiding this 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 :)
lighthouse-core/gather/driver.js
Outdated
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 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest nonRedundantServiceWorkers
-> activateCandidates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update
lighthouse-core/gather/driver.js
Outdated
return sw.status === 'activated'; | ||
}); | ||
|
||
const hasActiveServiceWorker = nonRedundantServiceWorkers.length && activeServiceWorker; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
lighthouse-core/gather/driver.js
Outdated
return sw.status === 'activated'; | ||
}); | ||
|
||
const hasActiveServiceWorker = activeServiceWorker; |
There was a problem hiding this comment.
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
.
LGTM 👍 |
* Wait for active serviceworker * Fix test cases * Review fixes * Review fix
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?