Skip to content

React Router 7 Library Mode: Navigation transactions are not created #16062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacquesg opened this issue Apr 12, 2025 · 4 comments · Fixed by getsentry/sentry-docs#13386
Closed

Comments

@jacquesg
Copy link

Environment

SaaS (https://sentry.io/)

Steps to Reproduce

Setup as per: https://docs.sentry.io/platforms/javascript/guides/react/features/react-router/v7/

Expected Result

Navigation transactions to be created.

Actual Result

No navigation transactions are created.

They are expected to be sprinkled between the NestJS lines in the screenshot. The pageload transaction is present though.

Image

Product Area

Unknown

Link

No response

DSN

No response

Version

No response

@getsantry
Copy link

getsantry bot commented Apr 12, 2025

Assigning to @getsentry/support for routing ⏲️

@getsantry getsantry bot moved this to Waiting for: Support in GitHub Issues with 👀 3 Apr 12, 2025
@jacquesg
Copy link
Author

jacquesg commented Apr 12, 2025

Extra information that may be useful:

import {
  createBrowserRouter,
  createRoutesFromChildren,
  matchRoutes,
  useLocation,
  useNavigationType,
} from 'react-router';
import * as Sentry from '@sentry/react';
import { routes } from '@generouted/react-router';

const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV7(createBrowserRouter);
const router = sentryCreateBrowserRouter(routes);

Sentry.init({
  dsn: config.sentry.dsn,
  environment: config.sentry.environment,
  release: `antaeus@${config.app.version}`,
  integrations: [
    Sentry.reactRouterV7BrowserTracingIntegration({
      useEffect,
      useLocation,
      useNavigationType,
      createRoutesFromChildren,
      matchRoutes,
    }),
  ],
  tracesSampleRate: 1.0,
});

const element = document.getElementById('root');
if (element) {
  const root = ReactDOM.createRoot(element);
  root.render(<App router={router} />);
}

where

import { RouterProvider, RouterProviderProps } from 'react-router';

export interface AppProps {
  router: RouterProviderProps['router'];
}

export default function App({ router }: AppProps) {
  return <RouterProvider router={router} />
}

@jacquesg
Copy link
Author

I have figure out what is going on here. Sentry.reactRouterV7BrowserTracingIntegration has a number of side-effects, which sentryCreateBrowserRouter depends on.

This means, the router object MUST be created after calling Sentry.init.

@cobyeastwood183 cobyeastwood183 transferred this issue from getsentry/sentry Apr 14, 2025
@getsantry getsantry bot moved this from Waiting for: Support to Waiting for: Product Owner in GitHub Issues with 👀 3 Apr 14, 2025
@chargome
Copy link
Member

Hey @jacquesg, thanks for filing this. Yes this checks out, I'll leave a comment in our docs to make this more visible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants