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

onLCP does not work on prerendered pages #268

Closed
domenic opened this issue Oct 18, 2022 · 2 comments · Fixed by #270
Closed

onLCP does not work on prerendered pages #268

domenic opened this issue Oct 18, 2022 · 2 comments · Fixed by #270

Comments

@domenic
Copy link

domenic commented Oct 18, 2022

Steps to reproduce:

  • I'm using Chrome 108.0.5355.0 (Official Build) dev (64-bit) ; maybe be sure to be at least at that revision.
  • Enable Prerender2 in chrome://flags. Not sure this is necessary anymore but let's just be sure.
  • Visit https://equatorial-longing-kick.glitch.me/ .
  • Click "This link should be prerendered"
  • Notice that the page was prerendered (document.prerendering was logged as true), but no LCP is logged.
  • Open a new tab, directly to https://equatorial-longing-kick.glitch.me/next.html .
  • Notice that this time we get LCP logged.

So it seems like if the page is loaded while prerendered, onLCP is never called. Maybe this is related to the README saying

CLS, FCP, FID, and LCP are not reported if the page was loaded in the background.

I noticed that there is some special handling for bfcache restore in https://github.com/GoogleChrome/web-vitals/blob/main/src/onLCP.ts#L92-L106 . Maybe there should be something similar for prerendering activation? (Prerendering activation can be detected using the prerenderingchange event on Document.)

@tunetheweb
Copy link
Member

@philipwalton I think this is due to a combination of this:

web-vitals/src/onLCP.ts

Lines 54 to 58 in dfbd06e

// The startTime attribute returns the value of the renderTime if it is
// not 0, and the value of the loadTime otherwise. The activationStart
// reference is used because LCP should be relative to page activation
// rather than navigation start if the page was prerendered.
const value = lastEntry.startTime - getActivationStart();

And this:

if (metric.value >= 0) {

As the LCP time for a prerendered page should always be less than the activation time, we get a negative LCP, and that is then filtered out. We should clamp it to 0, same as we do for TTFB.

I've tested with a copy of @domenic 's demo page here and it seem's to work: https://prerender-demos.glitch.me/

Presumably should do same for FCP too.

Happy to put together a PR if you agree.

@philipwalton
Copy link
Member

philipwalton commented Oct 18, 2022

Sure, if you have time. Otherwise I could probably do it pretty quickly later today.

Update: ahh, I see you submitted #270 already. I'll take a look later.

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 a pull request may close this issue.

3 participants