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

core(start-url): stay offline for entirety of offlinePass #9451

Merged
merged 8 commits into from
Aug 15, 2019

Conversation

patrickhulce
Copy link
Collaborator

Summary
tl;dr - StartUrl gatherer is not actually offline while it is checking for service worker start URL fetching. This PR fixes that.

In #6957, the start url gatherer was refactored to allow WebAppManifest to be part of core artifacts and avoid being double fetched. The code appeared to assume that the page was offline at the start of the afterPass because it went back online to fetch the manifest before going back offline. This wasn't actually the case though. Due to refactorings long ago in gather runner we actually always run the entirety of afterPass while online.

For pages with service workers that are always controlling the page this doesn't end up making much of a difference because of good ol' #709. However, if the service worker only handles requests while the page is in an offline state (not really clear how one does this), then all requests actually go out over the network and we trip our !response.fromServiceWorker line to falsely fail the page (which is normally a good thing because it means that all pages that didn't have a service worker didn't magically start passing when this bug was introduced! 😄)

Related Issues/PRs
fixes #9450

@patrickhulce patrickhulce requested a review from paulirish as a code owner July 24, 2019 21:59
@patrickhulce patrickhulce changed the title core(offline): stay offline for entirety of offlinePass core(start-url): stay offline for entirety of offlinePass Jul 24, 2019
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

nice catch. Ugh this gatherer just won't ever be happy :)

lighthouse-core/gather/gatherers/offline.js Show resolved Hide resolved
@@ -77,7 +93,7 @@ class StartUrl extends Gatherer {
if (!response.fromServiceWorker) {
return resolve({
statusCode: -1,
explanation: 'Unable to fetch start URL via service worker.',
explanation: 'Fetched start URL but not via service worker.',
Copy link
Member

Choose a reason for hiding this comment

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

it seems like this message is more confusing than the original (should this audit care about that it's fetchable like that?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now the message is indistinguishable from not being able to fetch it at all which is a problem IMO. The fact that it fetched but was falling back to disk cache or something is worth flagging. Totally up for whatever wording others feel captures this goal.

Copy link
Member

Choose a reason for hiding this comment

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

The start URL did respond, but not via a service worker

mostly trying to align with the text of the audit.. (where we dont talk about fetching, etc)

Copy link
Member

Choose a reason for hiding this comment

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

The fact that it fetched but was falling back to disk cache or something is worth flagging

I don't know if everyone knows the priority order here, though. If I'm looking at the start_url audit LH tells me

The start URL did respond, but not via a service worker

my first question would be "well why didn't LH try fetching via the SW? Do I need to force it somehow?"

It seems like the only important information is that LH tried to fetch it and the SW didn't return it. Just because it was in the disk cache during the LH run doesn't mean it will be for returning users, and isn't that the case we're testing for?

Alternatively, should we just call out the fromDiskCache case with a separate explanation?

@vercel vercel bot temporarily deployed to staging July 25, 2019 15:16 Inactive
const navigationRecord = loadData.networkRecords.filter(record => {
return URL.equalWithExcludedFragments(record.url, passContext.url) &&
record.fetchedViaServiceWorker;
}).pop(); // Take the last record that matches.

return passContext.driver.goOnline(passContext)
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment around L16 that the goOnline now happens in start-url which sequentially follows this gatherer?

Copy link
Member

Choose a reason for hiding this comment

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

actually it seems like the goOffline in L16 isnt needed anymore since starturl does it on its own. right

Copy link
Collaborator Author

@patrickhulce patrickhulce Jul 25, 2019

Choose a reason for hiding this comment

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

can you add a comment around L16 that the goOnline now happens in start-url which sequentially follows this gatherer?

well the goOnline that cleans this up actually happens in gather-runner that was the problem. each afterPass happens while online and each gatherer has to handle its own online/offline cycle. but yes comment is great idea 👍

actually it seems like the goOffline in L16 isnt needed anymore since starturl does it on its own. right

it's still needed to setup the offline for the load of the page, we do the offline check for both the page and the start url separately

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

nit on wording otherwise lgtm

@@ -77,7 +93,7 @@ class StartUrl extends Gatherer {
if (!response.fromServiceWorker) {
return resolve({
statusCode: -1,
explanation: 'Unable to fetch start URL via service worker.',
explanation: 'Fetched start URL but not via service worker.',
Copy link
Member

Choose a reason for hiding this comment

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

The start URL did respond, but not via a service worker

mostly trying to align with the text of the audit.. (where we dont talk about fetching, etc)

@vercel vercel bot temporarily deployed to staging August 14, 2019 15:30 Inactive
lighthouse-core/gather/gatherers/start-url.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/start-url.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/start-url.js Outdated Show resolved Hide resolved
evaluateAsync: unimplemented,
on: unimplemented,
off: unimplemented,
};
Copy link
Member

Choose a reason for hiding this comment

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

moving off bespoke mocks is good, but I have to say this is a nice model for this file :)

lighthouse-core/test/gather/gatherers/start-url-test.js Outdated Show resolved Hide resolved
assert.equal(artifactWithFragment.statusCode, 200);
const result = await gatherer.afterPass(passContext);
expect(mockDriver.goOffline).toHaveBeenCalled();
expect(mockDriver.goOnline).toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about an extra level of checking for these that it was offline when evaluateAsync was called, not just that off and on were both called?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like it as a separate test but not on every single one :) done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Offline pass doesn't always go offline
4 participants