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(fr): convert image-elements gatherer #12474

Merged
merged 17 commits into from
May 17, 2021
Merged

core(fr): convert image-elements gatherer #12474

merged 17 commits into from
May 17, 2021

Conversation

adamraine
Copy link
Member

@adamraine adamraine commented May 13, 2021

Opening as a draft to get some initial thoughts on the new test file which is not exhaustive yet. I restructured ImageElements a bit to make it easier to test.

Ref #11313

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.

This restructure is definitely an improvement, IMO, so this draft LGTM to polish if this is the first step we'd like to take here. We will eventually have to be much more aggressive with restructuring this gatherer to make it work well for other modes, but understood if you'd prefer to do it in small chunks 👍

I'll also throw out #12077 in case there was anything you were looking at restructuring that aligns with imminent breaking change work we'd like to tackle.


it('fetch size information for image with picture', () => {
const elements = [
{node: {}, src: 'https://example.com/a.png', isPicture: true, isCss: true, srcset: 'src'},
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW isPicture and isCss should never be true at the same time.

Copy link
Member Author

@adamraine adamraine May 13, 2021

Choose a reason for hiding this comment

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

I'm pretty sure the function this is testing is bugged. networkRecord will always be true because {} is truthy.

adamraine and others added 2 commits May 13, 2021 14:23
Co-authored-by: Patrick Hulce <patrick.hulce@gmail.com>
Co-authored-by: Patrick Hulce <patrick.hulce@gmail.com>
@adamraine
Copy link
Member Author

Possible second bug:

async fetchElementWithSizeInformation(driver, element) {
const url = element.src;
if (this._naturalSizeCache.has(url)) {
Object.assign(element, this._naturalSizeCache.get(url));
}

Shouldn't we return after the cache hit?

@patrickhulce
Copy link
Collaborator

heh, whoops, yes indeed @adamraine . at least that's a new one

@patrickhulce
Copy link
Collaborator

oh wait now that you mention it both of those little bugs come from that PR, both quite new then :)

@adamraine adamraine marked this pull request as ready for review May 13, 2021 21:22
@adamraine adamraine requested a review from a team as a code owner May 13, 2021 21:22
Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

also LGTM, nice job!

* @param {LH.Artifacts.ImageElement} element
*/
async fetchElementWithSizeInformation(driver, element) {
const url = element.src;
if (this._naturalSizeCache.has(url)) {
Object.assign(element, this._naturalSizeCache.get(url));
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👀

lighthouse-core/gather/gatherers/image-elements.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/image-elements.js Outdated Show resolved Hide resolved
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 work!

@adamraine adamraine merged commit 10e6300 into master May 17, 2021
@adamraine adamraine deleted the fr-image-elements branch May 17, 2021 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants