Skip to content

If the basename option is used with React Router 6 transactions are not created for navigation events.  #8413

Closed
@ngelotte

Description

@ngelotte

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

7.56.0

Framework Version

React 18

Link to Sentry event

No response

SDK Setup

Sentry.init({
        dsn:
            'MYDSN',
        integrations: [
            new Sentry.BrowserTracing({
                beforeNavigate: (context) => {
                    console.log("Navigating");
                    console.log(context);
                    return context;
                },
                // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
                tracePropagationTargets: ["graphql"],
                // See docs for support of different versions of variation of react router
                // https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/
                routingInstrumentation: Sentry.reactRouterV6Instrumentation(
                    React.useEffect,
                    useLocation,
                    useNavigationType,
                    createRoutesFromChildren,
                    matchRoutes
                ),
            }),
            new Sentry.Replay({
                networkDetailAllowUrls: ["graphql"],
                maskAllText: false,
                maskAllInputs: false,
                blockAllMedia: false
              })
        ],
        tracesSampleRate: 1.0,
        replaysSessionSampleRate: 1.0,
        replaysOnErrorSampleRate: 1.0,
        environment: config.EnvironmentName
    });

Steps to Reproduce

Setup React Router 6 like this:

const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouter(createBrowserRouter);
const router = suppressRouter
    ? null
    : sentryCreateBrowserRouter(
        createRoutesFromChildren(
            <Route
                path="/"
                element={RootElement}
                 <Fragment>
                  <Route
                      path="/stuff"
                      element={<Stuff />} />
                  <Route path="/" element={<Home />} />
              </Fragment>
           </Route>
        ) ,
        {
            basename: "/myapp"
        }
    );

Expected Result

Sentry would correctly hook into React Router and create transactions when navigating on the site even when basename is specified for React Router

Actual Result

Only the home page is captured all other navigations are ignored. If you comment out the option element where it has basename then everything works correctly. However, because of the way we are hosting multiple sites together I need to use the basename option.
This also means that the sentry-trace header is not attached to any requests that are not on the homepage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: reactIssues related to the Sentry React SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions