w3c / largest-contentful-paint

Specification for the LargestContentfulPaint API
https://w3c.github.io/largest-contentful-paint/
Other
88 stars 16 forks source link

Should we skip images with an existing LCP entry? #82

Open yoavweiss opened 2 years ago

yoavweiss commented 2 years ago

In https://wicg.github.io/largest-contentful-paint/#sec-add-lcp-entry step 2 ensures that elements that already fired an entry will not fire another entry again. I'd like to better understand the reasoning for it, as it seems counter-intuitive, at least in some cases. e.g. There could be a case where an image A of 50x50 is the LCP, followed by an image B that's 75x50. If A then gets resized to 100x50, we'd want the largest LCP candidate to be A with the right size, not B.

npm1 commented 2 years ago

I don't understand how that can happen in the first place. If A is 50x50, how does it suddenly then become 100x50? The only way I can see this happening is if the image container itself is expanded. Since we shrink the images based on intrinsic sizes, it wouldn't affect the LCP size. If instead you mean A gets a different image, then that's a different LCP candidate.

yoavweiss commented 2 years ago

One example could be where A is a background image of a node that truncates it, and then gets resized to no longer truncate it (or truncate it less).

npm1 commented 2 years ago

Oh I see, so this is specific to background images? How often would this happen? Are there use-cases for this? The main reason from my perspective is performance. Also, would this suggest shrinking the size if the candidate is shrank? That would complicate things as we'd have to go back to storing all LCP candidates.

yoavweiss commented 2 years ago

I guess this is also true for html-based images that had initially larger intrinsic size than their display dimensions, and were then changed to have larger dimensions.

yoavweiss commented 2 years ago

Also, would this suggest shrinking the size if the candidate is shrank?

No, for the same reasons we don't look into removed images.

noamr commented 2 years ago

Also, due to intersection being part of the size calc, can't a below-the-fold element receive a larger entry while scrolling? Sounds like this has to happen...

rik commented 2 years ago

Also, due to intersection being part of the size calc, can't a below-the-fold element receive a larger entry while scrolling?

The algorithm terminates whenever scroll or input events occur, since those are likely to introduce new content into the website.

noamr commented 2 years ago

Also, due to intersection being part of the size calc, can't a below-the-fold element receive a larger entry while scrolling?

The algorithm terminates whenever scroll or input events occur, since those are likely to introduce new content into the website.

Thanks, of course, I missed that!

yoavweiss commented 1 year ago

IMO, there's no strong reason to not fire LCP entries again. The next step is to get a PR going that removes the content set, as well as tests to go along with it.