Skip to content

Comments

ref(react): Remove lazy route machinery in favour of lazyRouteManifest#19466

Open
onurtemizkan wants to merge 3 commits intodevelopfrom
onur/clean-up-lazy-route-logic
Open

ref(react): Remove lazy route machinery in favour of lazyRouteManifest#19466
onurtemizkan wants to merge 3 commits intodevelopfrom
onur/clean-up-lazy-route-logic

Conversation

@onurtemizkan
Copy link
Collaborator

Following up on #19086

This removes the lazy route machinery (patchSpanEnd, trackLazyRouteLoad, createDeferredLazyRoutePromise, pendingLazyRouteLoads, deferredLazyRouteResolvers, shouldUpdateWildcardSpanName, tryUpdateSpanNameBeforeEnd, etc.) that was previously used to handle parameterized route naming for lazy routes.

The series of fixes for this over time (#17867, #17962, #18098, #18155, #18346, #18881, #18898) added increasingly complex race condition handling, deferred promise mechanisms, and span end patching, all trying to ensure correct transaction names when lazy routes hadn't loaded yet. With lazyRouteManifest introduced in #19086, we no longer need any of this. The manifest provides the parameterized route name upfront, without needing to wait for route resolution.

Removed:

  • patchSpanEnd and the entire span.end() monkey-patching mechanism
  • trackLazyRouteLoad / pendingLazyRouteLoads promise tracking
  • createDeferredLazyRoutePromise / resolveDeferredLazyRoutePromise deferred resolution
  • shouldUpdateWildcardSpanName / tryUpdateSpanNameBeforeEnd wildcard upgrade logic
  • __sentry_may_have_lazy_routes__ span flag
  • Dead matches parameter from handleNavigation and updatePageloadTransaction
  • AgnosticDataRouteMatch type import (only used for the removed matches parameter)

lazyRouteTimeout is deprecated with a runtime warning, pointing users to lazyRouteManifest.

The updatePageloadTransaction retains a manifest fallback for the case where matchRoutes returns no branches during initial pageload (lazy routes not yet loaded). handleNavigation doesn't need this as React Router only updates state.location when navigation completes (idle), so routes are already resolved.

Copy link

@cursor cursor bot left a comment

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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.62 kB - -
@sentry/browser - with treeshaking flags 24.12 kB - -
@sentry/browser (incl. Tracing) 42.42 kB - -
@sentry/browser (incl. Tracing, Profiling) 47.09 kB - -
@sentry/browser (incl. Tracing, Replay) 81.24 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.94 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 98.2 kB - -
@sentry/browser (incl. Feedback) 42.43 kB - -
@sentry/browser (incl. sendFeedback) 30.29 kB - -
@sentry/browser (incl. FeedbackAsync) 35.34 kB - -
@sentry/browser (incl. Metrics) 26.79 kB - -
@sentry/browser (incl. Logs) 26.93 kB - -
@sentry/browser (incl. Metrics & Logs) 27.61 kB - -
@sentry/react 27.37 kB - -
@sentry/react (incl. Tracing) 44.67 kB -0.21% -91 B 🔽
@sentry/vue 30.07 kB - -
@sentry/vue (incl. Tracing) 44.27 kB - -
@sentry/svelte 25.64 kB - -
CDN Bundle 28.16 kB - -
CDN Bundle (incl. Tracing) 43.25 kB - -
CDN Bundle (incl. Logs, Metrics) 29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.08 kB - -
CDN Bundle (incl. Tracing, Replay) 80.13 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.53 kB - -
CDN Bundle - uncompressed 82.34 kB - -
CDN Bundle (incl. Tracing) - uncompressed 128.06 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.18 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.84 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.94 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.76 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.66 kB - -
@sentry/nextjs (client) 47.17 kB - -
@sentry/sveltekit (client) 42.89 kB - -
@sentry/node-core 52.18 kB +0.02% +8 B 🔺
@sentry/node 173.45 kB +0.01% +9 B 🔺
@sentry/node - without tracing 97.33 kB +0.01% +9 B 🔺
@sentry/aws-serverless 113.13 kB +0.01% +7 B 🔺

View base workflow run

@onurtemizkan onurtemizkan force-pushed the onur/clean-up-lazy-route-logic branch from e7ab1da to 38bf328 Compare February 23, 2026 14:00
Comment on lines +937 to 947
if (source === 'route') {
startBrowserTracingNavigationSpan(client, {
name,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.react.reactrouter_v${version}`,
},
});
}
}
Copy link

Choose a reason for hiding this comment

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

Bug: The manifest fallback path in handleNavigation creates new navigation spans without checking for duplicates, unlike the primary path, leading to multiple spans for a single navigation.
Severity: MEDIUM

Suggested Fix

The manifest fallback path in handleNavigation should replicate the duplicate detection logic from the primary path. Before creating a new span, check activeNavigationSpans for an existing navigation. If one exists, update it. If not, create a new span and add it to the activeNavigationSpans map to ensure it is tracked.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/react/src/reactrouter-compat-utils/instrumentation.tsx#L920-L947

Potential issue: When `handleNavigation` is called multiple times while `branches` is
null (e.g., during a transition before lazy routes are loaded), the manifest fallback
logic is triggered. This path creates a new navigation span via
`startBrowserTracingNavigationSpan` on each invocation. Unlike the primary path, it does
not check the `activeNavigationSpans` map for existing navigations or add the new span
to it. This results in multiple untracked spans for the same logical navigation,
bypassing deduplication and potentially causing a memory leak.

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