= new Set(); const SentryRoutes: React.FC
= (props: P) => { const isMountRenderPass = React.useRef(true); @@ -527,10 +542,14 @@ export function createV6CompatibleWithSentryReactRouterRouting
{ - allRoutes.push(...getChildRoutesRecursively(route)); + const extractedChildRoutes = getChildRoutesRecursively(route); + + extractedChildRoutes.forEach(r => { + allRoutes.add(r); + }); }); - updatePageloadTransaction(getActiveRootSpan(), location, routes, undefined, undefined, allRoutes); + updatePageloadTransaction(getActiveRootSpan(), location, routes, undefined, undefined, Array.from(allRoutes)); isMountRenderPass.current = false; } else { handleNavigation({ @@ -538,7 +557,7 @@ export function createV6CompatibleWithSentryReactRouterRouting
{
+ const actual = jest.requireActual('@sentry/browser');
+ return {
+ ...actual,
+ startBrowserTracingNavigationSpan: (...args: unknown[]) => {
+ mockStartBrowserTracingNavigationSpan(...args);
+ return actual.startBrowserTracingNavigationSpan(...args);
+ },
+ startBrowserTracingPageLoadSpan: (...args: unknown[]) => {
+ mockStartBrowserTracingPageLoadSpan(...args);
+ return actual.startBrowserTracingPageLoadSpan(...args);
+ },
+ };
+});
+
+jest.mock('@sentry/core', () => {
+ const actual = jest.requireActual('@sentry/core');
+ return {
+ ...actual,
+ getRootSpan: () => {
+ return mockRootSpan;
+ },
+ };
+});
+
+describe('React Router Descendant Routes', () => {
+ function createMockBrowserClient(): BrowserClient {
+ return new BrowserClient({
+ integrations: [],
+ tracesSampleRate: 1,
+ transport: () => createTransport({ recordDroppedEvent: () => undefined }, _ => Promise.resolve({})),
+ stackParser: () => [],
+ });
+ }
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ getCurrentScope().setClient(undefined);
+ });
+
+ describe('withSentryReactRouterV6Routing', () => {
+ it('works with descendant wildcard routes - pageload', () => {
+ const client = createMockBrowserClient();
+ setCurrentClient(client);
+
+ client.addIntegration(
+ reactRouterV6BrowserTracingIntegration({
+ useEffect: React.useEffect,
+ useLocation,
+ useNavigationType,
+ createRoutesFromChildren,
+ matchRoutes,
+ }),
+ );
+ const SentryRoutes = withSentryReactRouterV6Routing(Routes);
+
+ const DetailsRoutes = () => (
+