Skip to content

Maximum Call Stack Size Exceeded When Using Sentry.withSentryReactRouterV7Routing Wrapper #14848

Closed
@okvic77

Description

@okvic77

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

8.47.0

Framework Version

React 19.0.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from "@sentry/react";
import { useEffect, useMemo } from "react";
import {
  useLocation,
  useNavigationType,
  createRoutesFromChildren,
  matchRoutes,
  createBrowserRouter,
  useRouteError,
} from "react-router";
Sentry.init({
  dsn: sentryDSN,
  release: VERSION,
  environment: env,
  tracesSampleRate: 0.1,
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,
  // If the entire session is not sampled, use the below sample rate to sample
  // sessions when an error occurs.
  replaysOnErrorSampleRate: 0.1,
  integrations: [
    // Sentry.browserTracingIntegration(),

    Sentry.reactRouterV7BrowserTracingIntegration({
      useEffect,
      useLocation,
      useNavigationType,
      createRoutesFromChildren,
      matchRoutes,
      instrumentNavigation: false,
      instrumentPageLoad: false,
    }),

    Sentry.replayIntegration(),
  ],
  // debug: true,
  // tracePropagationTargets: ["localhost", window.location.hostname],
});
const Routes = Sentry.withSentryReactRouterV7Routing(RoutesOriginal);

Steps to Reproduce

Issue Description

  1. I updated and deployed the application to the staging environment.
  2. After deployment, I encountered a Maximum call stack size exceeded error consistently.

Observations

  • The error occurs specifically when I wrap the Routes variable with the Sentry.withSentryReactRouterV7Routing wrapper.
  • If I use the original Routes value (without the Sentry wrapper), the app works as expected.

Debugging Insights

  • During my debugging session, I identified the function getChildRoutesRecursively as the source of the issue.
  • The allRoutes array keeps increasing indefinitely, repeating the same values, which seems to cause the stack overflow.

Expected Result

No error

Actual Result

Video of the error

https://share.cleanshot.com/DKK4fppplggwQKPFpV34

Metadata

Metadata

Assignees

Labels

Package: browserIssues related to the Sentry Browser SDK

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions