fix(browser): Source FCP from web-vitals onFCP and rebase FP against activationStart - #23032
Conversation
size-limit report 📦
|
…t `activationStart` FP and FCP were the only vitals still read straight off the `paint` observer, storing the raw `entry.startTime`. On a page prerendered via the Speculation Rules API, paint timestamps are relative to the prerender navigation start, so both values carried the entire time the document sat dormant in the prerender buffer. FCP now goes through web-vitals' `onFCP` like CLS/LCP/TTFB/INP already do, which applies the `activationStart` correction itself and defers registration until activation. web-vitals has no `onFP`, so FP stays on the paint observer and applies the same correction inline. `onFCP` costs nothing in bundle size: `onCLS` already imports it, and that import is static.
21daec9 to
b2a1abc
Compare
onFCP and rebase FP against activationStart
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b2a1abc. Configure here.
| return addFcpInstrumentationHandler(({ metric }) => { | ||
| _measurements['fcp'] = { value: metric.value, unit: 'millisecond' }; | ||
| }); | ||
| } |
There was a problem hiding this comment.
FCP dropped before prerender activation
High Severity
Sourcing fcp from web-vitals onFCP waits for page activation before reporting. On a Speculation Rules prerender the pageload span often finishes during the hidden prerender (load plus idle timeout), so finalizeWebVitals removes the handler before onFCP runs and First Contentful Paint never reaches the span.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit b2a1abc. Configure here.
2 similar comments
Lms24
left a comment
There was a problem hiding this comment.
Sorry for the late review! LGTM!
The correction was applied when the paint entry arrived, but on a prerendered page that happens while the document is still in the prerender buffer, before the user has activated it. `activationStart` is 0 at that point, so subtracting it did nothing and FP kept the prerender-relative timestamp. The web-vitals-sourced metrics avoid this because they only start observing after activation. FP comes off a buffered paint observer we register at init, so it can't. Store the raw `startTime` instead and do the subtraction in `addWebVitalsToSpan`, by which point activation has happened. Also rewrites the prerender test, which stubbed a non-zero `activationStart` before emitting any entries and so never covered the prerender window.


Corrects First Paint and First Contentful Paint on the pageload span for pages prerendered via the Speculation Rules API.
Both were read straight off the
paintobserver as a rawentry.startTime, so on a prerendered page they carried the whole time the document sat in the prerender buffer.Rather than patch the arithmetic in two places I moved FCP onto web-vitals'
onFCP, which is where CLS/LCP/TTFB/INP already get theiractivationStartcorrection.web-vitals has no
onFP, so FP stays on the paint observer with the correction applied inline.