GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.47k stars 410 forks source link

Fix interaction count after bfcache restore #505

Closed BenoitZugmeyer closed 1 month ago

BenoitZugmeyer commented 1 month ago

While reviewing the INP implementation, I noticed what I believe is a bug in interactions.ts. Currently, prevInteractionCount is always 0, but based on the comment

// Used to store the interaction count after a bfcache restore, since p98
// interaction latencies should only consider the current navigation.

I believe prevInteractionCount should be set to getInteractionCount() when reset, so the next time getInteractionCountForNavigation() is called it should return 0 instead of the count of interactions that happened before the bfcache restore.

philipwalton commented 1 month ago

Thanks @BenoitZugmeyer, I believe you're right, and that matches how the code looked in v3.5.2: https://github.com/GoogleChrome/web-vitals/blob/v3.5.2/src/onINP.ts#L247-L249

Looks like this got changed in the refactor for v4...

philipwalton commented 1 month ago

This has been released in v4.2.2.