Skip to content

feat(browser): Start a navigation span for bfcache restores - #23748

Draft
logaretm wants to merge 1 commit into
awad/js-1019-soft-nav-web-vitals-spansfrom
awad/bfcache-navigation-span
Draft

feat(browser): Start a navigation span for bfcache restores#23748
logaretm wants to merge 1 commit into
awad/js-1019-soft-nav-web-vitals-spansfrom
awad/bfcache-navigation-span

Conversation

@logaretm

@logaretm logaretm commented Aug 28, 2026

Copy link
Copy Markdown
Member

Starts a navigation span when the page is restored from the back/forward cache.

A restore resurrects the frozen document, so there is no document load and no usable history event: popstate either doesn't fire or is swallowed because the URL is unchanged. Without a span of its own, everything after the restore joins the trace the page had before it was frozen, which misattributes errors and breadcrumbs as much as vitals.

It lives in browserTracingIntegration rather than bfcacheIntegration so it doesn't depend on an opt-in integration being enabled, and carries browser.navigation.type: bfcache since a restore is near-instant and would otherwise drag navigation duration percentiles down with no way to tell it apart.

Stacked on #23425.

… bfcache

Prototype. A bfcache restore resurrects the frozen document, so there is
no document load and no usable history event: `popstate` either doesn't
fire or is swallowed, because the URL is unchanged from when the page was
frozen. Two independent guards in the existing path suppress it, neither
written with bfcache in mind, so there is no small nudge that gets a span
out of it.

Without one, everything after the restore joins the trace the page had
before it was frozen, separated by however long it sat in the cache. That
misattributes errors, breadcrumbs, clicks and fetches, not just the web
vitals that prompted this.

The span is started from a `pageshow` listener in `browserTracingIntegration`
rather than `bfcacheIntegration`, so it does not depend on an opt-in
integration that is about hit/miss diagnostics. It is gated on
`instrumentNavigation` and on by default.

It carries `browser.navigation.type: bfcache`. A restore is near-instant,
so without a way to filter these out they would drag navigation duration
percentiles down exactly the way bfcache vitals would have dragged LCP.

The span deliberately starts at the `pageshow` event rather than from
`PerformanceNavigationTiming`, which is not replaced on restore and still
describes the original document load.

Known gap, pinned by a test: `bfcacheIntegration` registers its own
`pageshow` listener from `setupOnce`, which core always runs before every
`afterAllSetup`, so its hit/miss metric is emitted before this span exists
and still lands on the pre-freeze trace.
@logaretm logaretm changed the title awad/bfcache navigation span feat(browser): Report web vitals for bfcache restores Aug 28, 2026
@logaretm
logaretm force-pushed the awad/bfcache-navigation-span branch from c306449 to 831a206 比较 August 28, 2026 18:39
@logaretm logaretm changed the title feat(browser): Report web vitals for bfcache restores feat(browser): Start a navigation span for bfcache restores Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.56 kB added added
@sentry/browser - with treeshaking flags 26.92 kB added added
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB added added
@sentry/browser (incl. Tracing) 49.6 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 49.61 kB added added
@sentry/browser (incl. Tracing, Profiling) 52.56 kB added added
@sentry/browser (incl. Tracing, Replay) 89.07 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 78.37 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 93.76 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 106.74 kB added added
@sentry/browser (incl. Feedback) 46.05 kB added added
@sentry/browser (incl. sendFeedback) 33.62 kB added added
@sentry/browser (incl. FeedbackAsync) 38.73 kB added added
@sentry/browser (incl. Metrics) 29.51 kB added added
@sentry/browser (incl. Logs) 29.8 kB added added
@sentry/browser (incl. Metrics & Logs) 30.43 kB added added
@sentry/react 30.3 kB added added
@sentry/react (incl. Tracing) 51.77 kB added added
@sentry/vue 35.69 kB added added
@sentry/vue (incl. Tracing) 51.8 kB added added
@sentry/svelte 28.59 kB added added
CDN Bundle 30.35 kB added added
CDN Bundle (incl. Tracing) 50.12 kB added added
CDN Bundle (incl. Logs, Metrics) 32.58 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 52.03 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 73.21 kB added added
CDN Bundle (incl. Tracing, Replay) 87.63 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 89.51 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 93.61 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 95.56 kB added added
CDN Bundle - uncompressed 89.95 kB added added
CDN Bundle (incl. Tracing) - uncompressed 149.96 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 155.65 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.52 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 269.44 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 275.12 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 283.14 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 288.81 kB added added
@sentry/nextjs (client) 54.19 kB added added
@sentry/sveltekit (client) 49.99 kB added added
@sentry/core/server 65.44 kB added added
@sentry/core/browser 51.84 kB added added
@sentry/node 123.12 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.23 kB added added
@sentry/node - without tracing 87.75 kB added added
@sentry/node - without channel injection 102.78 kB added added
@sentry/aws-serverless 95.91 kB added added
@sentry/cloudflare (withSentry) - minified 200.51 kB added added
@sentry/cloudflare (withSentry) 498.77 kB added added

注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

1 participant