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(tsc): fix ImageUsage artifact type and gather bug #5113

Merged
merged 4 commits into from
May 4, 2018

Conversation

brendankenny
Copy link
Member

The type for the ImageUsage artifact accidentally left off the optional image width and height, which made using it in the image-aspect-ratio audit impossible before. Fixed the artifact and removed the @ts-nocheck from the audit.

In the process, uncovered a bug in the gatherer. At some point shifting types made the extra fetch of size information never run for css or <picture> images. As a result, the naturalWidth and naturalHeight was being left at Number.MAX_VALUE for those and so the wastedPercent for those images was 100% in the uses-responsive-images audit :)

There was a clue in the smoke code coverage, but we hadn't noticed yet :)

Fixed the bug and added more specific expectations for that audit.

// Images within `picture` behave strangely and natural size information isn't accurate,
// CSS images have no natural size information at all.
// Try to get the actual size if we can.
const elementPromise = (element.isPicture || element.isCss) && element.networkRecord ?
Copy link
Member Author

Choose a reason for hiding this comment

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

this was the bug. element.networkRecord was never defined at this point

Copy link
Collaborator

@patrickhulce patrickhulce 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! good news is looks like this was introduced just 11 days ago so no one's bumped into it yet :) https://github.com/GoogleChrome/lighthouse/pull/5019/files#diff-a76f9d68fa433ad16daad08121c7411fR182

// Images within `picture` behave strangely and natural size information isn't accurate,
// CSS images have no natural size information at all.
// Try to get the actual size if we can.
if (element.isPicture || element.isCss) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we maintain the original concern and only fetch when we can find the network record? fetchElementWithSize is the expensive path

Copy link
Member Author

Choose a reason for hiding this comment

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

should we maintain the original concern and only fetch when we can find the network record?

Only uses-responsive-images seems to use naturalWidth/naturalHeight from css/<picture> images, and it requires a networkRecord to work, so makes sense

Copy link
Member Author

Choose a reason for hiding this comment

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

when we can find the network record?

...actually this conversation clearly shows that it should have been an optional property...

@brendankenny
Copy link
Member Author

good news is looks like this was introduced just 11 days ago

lol, hadn't looked at the blame yet :) Shows the danger of trying to do a Partial<> without looking deeper at the logic (or living without tests). networkRecords isn't actually used in fetchElementWithSizeInformation so it seemed fine to put first.

@brendankenny
Copy link
Member Author

sorry for the expanding scope, but this should properly reflect the ImageUsage artifact now. Logic was already in place to check if there wasn't a networkRecord, but had to do some slight rearranging to convince the compiler of this.

@@ -55,11 +57,15 @@ class OffscreenImages extends ByteEfficiencyAudit {
}

/**
* @param {!Object} image
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure how this slipped by :)

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

wfm!

@brendankenny brendankenny merged commit 91aa8d2 into master May 4, 2018
@brendankenny brendankenny deleted the tsimageusage branch May 4, 2018 19:21
kdzwinel pushed a commit to kdzwinel/lighthouse that referenced this pull request Aug 16, 2018
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.

2 participants