Skip to content

Conversation

@onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Jan 29, 2026

This PR will resolve the core reason for the series of fixes / handling for automatic lazy-route resolution for a while.

Related: #18898, #18881, #18346, #18155, #18098, #17962, #17867, #17438, #17277

The core issue we have been trying to tackle is not having access to the complete route hierarchy when asynchronously loaded lazy routes are used. React Router provides a route manifest that we can use while matching parameterized transaction names with routes in all cases except this lazy-routes pattern.

This problem has been discussed on React Router:

While this has been addressed for Remix / React Router (Framework Mode), it's still not available in Library Mode. The manifest contains the lazily-loaded route, only when it's navigated to. While waiting for navigation, our transactions can be dropped for several reasons, such as user behaviour like switching tabs (document.hidden guard), hitting timeouts like idleTimeout, and potentially other reasons. This results in incomplete transaction naming with leftover wildcards, which caused broken aggregation on the Sentry dashboard.

The series of attempts to fix this while keeping automatic route discovery has been prone to race conditions and required special-case handling of each edge case scenario, also requiring a considerable amount of internal logic, affecting our readability and performance. At the end, all failed in giving completely robust and deterministic results on the customers' side.

This PR proposes a new option: lazyRouteManifest specifically for lazy routes. This will let us have initial information about the route hierarchy. So we can assign correct parameterized transaction names without needing to wait for navigated state.

It's a static array of routes in parameterized format (needs to be maintained by the users on route hierarchy updates) like:

Sentry.reactRouterV7BrowserTracingIntegration({
  // ...
  enableAsyncRouteHandlers: true
  lazyRouteManifest: [
    '/',
    '/pricing',
    '/features',
    
    '/login',
    '/signup',
    '/forgot-password',
    '/reset-password/:token',
    
    '/org/:orgSlug',
    '/org/:orgSlug/dashboard',
    '/org/:orgSlug/projects',
    '/org/:orgSlug/projects/:projectId',
    '/org/:orgSlug/projects/:projectId/settings',
    '/org/:orgSlug/projects/:projectId/issues',
    '/org/:orgSlug/projects/:projectId/issues/:issueId',
    '/org/:orgSlug/team',
    '/org/:orgSlug/team/:memberId',
    '/org/:orgSlug/settings',
    '/org/:orgSlug/billing',
    
    '/admin',
    '/admin/users',
    '/admin/users/:userId',
    '/admin/orgs',
    '/admin/orgs/:orgId',
  ],
})
  • This will only be active when enableAsyncRouteHandlers is set to true
  • To match URLs with given routes, we mimic React Router's own implementation.
  • When this is not provided or fails, it falls back to the current behaviour
  • This manifest is primarily for lazy routes, but the users can also add their non-lazy routes here for convenience or consistency.
  • Also added E2E tests that will fail when (if at some point) React Router manifests include the lazy routes before navigation, so we'll be aware and plan depending on that manifest instead.
  • We can do a cleanup for the race-condition / edge-case handling part of the code in a follow-up PR.

Closes #19090 (added automatically)

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.33 kB - -
@sentry/browser - with treeshaking flags 23.83 kB - -
@sentry/browser (incl. Tracing) 42.14 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.79 kB - -
@sentry/browser (incl. Tracing, Replay) 80.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.41 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.47 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 97.66 kB - -
@sentry/browser (incl. Feedback) 42.05 kB - -
@sentry/browser (incl. sendFeedback) 30.02 kB - -
@sentry/browser (incl. FeedbackAsync) 35.01 kB - -
@sentry/browser (incl. Metrics) 26.43 kB - -
@sentry/browser (incl. Logs) 26.58 kB - -
@sentry/browser (incl. Metrics & Logs) 27.25 kB - -
@sentry/react 27.06 kB - -
@sentry/react (incl. Tracing) 44.39 kB +0.04% +17 B 🔺
@sentry/vue 29.76 kB - -
@sentry/vue (incl. Tracing) 43.94 kB - -
@sentry/svelte 25.34 kB - -
CDN Bundle 27.9 kB - -
CDN Bundle (incl. Tracing) 42.93 kB - -
CDN Bundle (incl. Logs, Metrics) 28.74 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 43.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 67.68 kB - -
CDN Bundle (incl. Tracing, Replay) 79.67 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.54 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.12 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.04 kB - -
CDN Bundle - uncompressed 81.61 kB - -
CDN Bundle (incl. Tracing) - uncompressed 127.16 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.45 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 129.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 207.83 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.76 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 246.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.37 kB - -
@sentry/nextjs (client) 46.73 kB - -
@sentry/sveltekit (client) 42.51 kB - -
@sentry/node-core 52.08 kB -0.01% -2 B 🔽
@sentry/node 166.08 kB -0.01% -2 B 🔽
@sentry/node - without tracing 93.83 kB -0.01% -1 B 🔽
@sentry/aws-serverless 109.36 kB - -

View base workflow run

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 2 potential issues.

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

export { createAsyncHandlerProxy, handleAsyncHandlerResult, checkRouteForAsyncHandler } from './lazy-routes';

// Route manifest exports
export { matchRouteManifest } from './route-manifest';
Copy link

Choose a reason for hiding this comment

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

Unused export of matchRouteManifest from index.ts

Low Severity

The matchRouteManifest function is exported from index.ts but this export is never used. Both consumers import directly from ./route-manifest instead: utils.ts imports from './route-manifest' and the test file imports from '../../src/reactrouter-compat-utils/route-manifest'. This export is dead code that adds unnecessary noise to the public API surface.

Fix in Cursor Fix in Web

normalizedPathname = normalizedPathname.slice(base.length) || '/';
}
}
}
Copy link

Choose a reason for hiding this comment

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

Duplicated basename stripping logic in route-manifest.ts

Low Severity

The inline basename stripping logic in matchRouteManifest (lines 16-26) duplicates the existing stripBasenameFromPathname function in utils.ts (lines 144-163). Both implementations perform case-insensitive basename matching, handle trailing slashes, verify segment boundaries, and return the stripped pathname or '/'. The existing function could be exported and reused to avoid maintaining duplicate logic.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

feat(react): Add lazyRouteManifest option to resolve lazy-route names

2 participants