Skip to content

fix(browser): Source FCP from web-vitals onFCP and rebase FP against activationStart - #23032

Merged
logaretm merged 2 commits into
developfrom
awad/prerender-fcp-fp-activationstart
Aug 28, 2026
Merged

fix(browser): Source FCP from web-vitals onFCP and rebase FP against activationStart#23032
logaretm merged 2 commits into
developfrom
awad/prerender-fcp-fp-activationstart

Conversation

@logaretm

@logaretm logaretm commented Aug 4, 2026

Copy link
Copy Markdown
Member

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 paint observer as a raw entry.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 their activationStart correction.

web-vitals has no onFP, so FP stays on the paint observer with the correction applied inline.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.56 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.68 kB +0.1% +46 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.7 kB +0.12% +55 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.62 kB +0.12% +59 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.15 kB +0.07% +56 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.56 kB +0.06% +39 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.85 kB +0.06% +54 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.79 kB +0.06% +53 B 🔺
@sentry/browser (incl. Feedback) 46.05 kB - -
@sentry/browser (incl. sendFeedback) 33.62 kB - -
@sentry/browser (incl. FeedbackAsync) 38.73 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.3 kB - -
@sentry/react (incl. Tracing) 50.9 kB +0.12% +60 B 🔺
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.93 kB +0.12% +57 B 🔺
@sentry/svelte 28.59 kB - -
CDN Bundle 30.35 kB - -
CDN Bundle (incl. Tracing) 49.29 kB +0.09% +43 B 🔺
CDN Bundle (incl. Logs, Metrics) 32.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.19 kB +0.08% +40 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB - -
CDN Bundle (incl. Tracing, Replay) 86.8 kB +0.07% +58 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.67 kB +0.06% +48 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.71 kB +0.09% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.59 kB +0.08% +68 B 🔺
CDN Bundle - uncompressed 89.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.96 kB +0.08% +117 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.65 kB +0.08% +117 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.46 kB +0.05% +117 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.13 kB +0.05% +117 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.16 kB +0.05% +117 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.83 kB +0.05% +117 B 🔺
@sentry/nextjs (client) 53.48 kB +0.11% +55 B 🔺
@sentry/sveltekit (client) 49.13 kB +0.11% +52 B 🔺
@sentry/core/server 65.44 kB - -
@sentry/core/browser 51.84 kB - -
@sentry/node 123.16 kB +0.02% +13 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.23 kB - -
@sentry/node - without tracing 87.75 kB +0.04% +27 B 🔺
@sentry/node - without channel injection 102.83 kB +0.02% +19 B 🔺
@sentry/aws-serverless 95.91 kB +0.03% +24 B 🔺
@sentry/cloudflare (withSentry) - minified 200.51 kB - -
@sentry/cloudflare (withSentry) 498.77 kB - -

View base workflow run

…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.
@logaretm
logaretm force-pushed the awad/prerender-fcp-fp-activationstart branch from 21daec9 to b2a1abc Compare August 13, 2026 16:14
@logaretm logaretm changed the title fix(browser): Rebase FP/FCP against activationStart for prerendered pages fix(browser): Source FCP from web-vitals onFCP and rebase FP against activationStart Aug 13, 2026
@logaretm
logaretm marked this pull request as ready for review August 13, 2026 16:33
@logaretm
logaretm requested a review from a team as a code owner August 13, 2026 16:33
@logaretm
logaretm requested review from Lms24 and msonnb and removed request for a team August 13, 2026 16:33

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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' };
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b2a1abc. Configure here.

Comment thread packages/browser-utils/src/web-vitals/tracking.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

👋 @Lms24, @msonnb — Please review this PR when you get a chance!

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

👋 @Lms24, @msonnb — Please review this PR when you get a chance!

@github-actions

Copy link
Copy Markdown
Contributor

👋 @Lms24, @msonnb — Please review this PR when you get a chance!

@Lms24 Lms24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@logaretm
logaretm merged commit 9350361 into develop Aug 28, 2026
551 of 553 checks passed
@logaretm
logaretm deleted the awad/prerender-fcp-fp-activationstart branch August 28, 2026 18:14
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 this pull request may close these issues.

2 participants