Skip to content

fix(js): end browser trace roots at real activity, not idle-timeout padding#70

Merged
DriesH merged 1 commit into
research/tracing-framework-routersfrom
fix/browser-tracing-idle-end-time
Jul 9, 2026
Merged

fix(js): end browser trace roots at real activity, not idle-timeout padding#70
DriesH merged 1 commit into
research/tracing-framework-routersfrom
fix/browser-tracing-idle-end-time

Conversation

@DriesH

@DriesH DriesH commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Stacked on #69 — targets research/tracing-framework-routers, so the diff here is just this fix.

Summary

Browser pageload / navigation root spans were reporting durations inflated by the whole idleTimeout. A childless root (no fetch/xhr children during its window) closed at now() = start + idleTimeout, so a real ~488ms pageload showed as 2488ms with idleTimeout: 2000.

Root cause

IdleRootController trims a root's end to the last child's end on idle close, but fell back to now() when there were no children (lastChildEndTime ?? now()), padding the duration by the full idle window. endNow() (route change / pagehide) had the same now() behavior.

Fix

Roots now trim to an injected end floor instead of now():

  • pageload → Navigation Timing loadEventEnd (the browser's "page finished loading" mark; falls back to domContentLoadedEventEnd, then now()).
  • navigation → the nav's own start (an instant client-side nav trims to ~0).
  • endNow() trims the same way, except when a child is still in flight — then it keeps now() so in-progress work isn't cut short.

Fetch-heavy roots are unchanged; they already trimmed to the last child.

Tests

  • IdleRootController: childless roots trim to the floor (not now()); endNow trims unless a child is open.
  • navigationTiming: computePageloadEndNano (loadEventEnd → domContentLoadedEventEnd → now fallbacks).
  • Full @flareapp/js suite green (154), typecheck + lint clean.

Verified in the JS playground against a local Flare: the pageload that read 2488ms now reports its real ~488ms.

…adding

A childless pageload/navigation root closed at now() (start + idleTimeout), inflating its duration by the whole idle window (e.g. a 488ms pageload reported as 2488ms with idleTimeout=2000). Roots now trim to an injected end floor: pageload -> Navigation Timing loadEventEnd, navigation -> its own start; endNow() trims the same way unless a child is still in flight.
@DriesH DriesH merged commit 10d91ce into research/tracing-framework-routers Jul 9, 2026
3 checks passed
@DriesH DriesH deleted the fix/browser-tracing-idle-end-time branch July 9, 2026 12:16
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.

1 participant