Skip to content

LCP Loses Entry Element After SPA Route Change #561

@dmitiiv

Description

@dmitiiv

When using the web-vitals library to track the Largest Contentful Paint (LCP) metric in a Single Page Application (SPA), we encounter an issue where the LCP entry element is lost upon changing routes. This problem arises because the web-vitals library captures the LCP metric based on the elements rendered on the page at the time of measurement.

In SPAs, content is often loaded dynamically, and when navigating to a new route, the relevant content may not be fully rendered or may change, causing the library to lose track of the largest contentful element. As a result, the reported LCP value may not accurately reflect the user experience, leading to misleading performance metrics.

How to reproduce

  1. Create any default SPA (Vite etc)
  2. Start listerning onLCP (web-vitals or web-vitals/attribution)
  3. Change route before the scroll on any other interaciton

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions