Skip to content

Commit 1a7acb3

Browse files
JPeer264claude
andcommitted
fixup! fix(react-router): Resolve the Cloudflare entry in Workers and skip trace meta tags in prerendered pages
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0c368ad commit 1a7acb3

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎packages/react-router/src/server/wrapSentryHandleRequest.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ export function wrapSentryHandleRequest(
6666
routerContext: EntryContext,
6767
loadContext: AppLoadContext | RouterContextProvider,
6868
) {
69-
const parameterizedPath =
70-
routerContext?.staticHandlerContext?.matches?.[routerContext.staticHandlerContext.matches.length - 1]?.route.path;
69+
const matches = routerContext?.staticHandlerContext?.matches;
70+
// An index route has no `path` of its own and renders at its nearest ancestor's path, or at `/`.
71+
const parameterizedPath = matches?.length
72+
? ([...matches].reverse().find(match => match.route.path)?.route.path ?? '/')
73+
: undefined;
7174

7275
const activeSpan = getActiveSpan();
7376
const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;

‎packages/react-router/test/server/wrapSentryHandleRequest.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,45 @@ describe('wrapSentryHandleRequest', () => {
7474
});
7575
});
7676

77+
test('should name an index route after its nearest ancestor path, or `/`', async () => {
78+
const mockRootSpan = { setAttributes: vi.fn() };
79+
80+
(getActiveSpan as unknown as ReturnType<typeof vi.fn>).mockReturnValue({});
81+
(getRootSpan as unknown as ReturnType<typeof vi.fn>).mockReturnValue(mockRootSpan);
82+
83+
const wrappedHandler = wrapSentryHandleRequest(vi.fn().mockResolvedValue('test'));
84+
85+
const rootIndexContext = {
86+
staticHandlerContext: { matches: [{ route: { path: '' } }, { route: { index: true } }] },
87+
} as any;
88+
await wrappedHandler(new Request('https://nacho.queso/'), 200, new Headers(), rootIndexContext, {} as any);
89+
90+
expect(mockRootSpan.setAttributes).toHaveBeenLastCalledWith({
91+
[HTTP_ROUTE]: '/',
92+
[SENTRY_SEGMENT_NAME_SOURCE]: 'route',
93+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.request_handler',
94+
});
95+
96+
const nestedIndexContext = {
97+
staticHandlerContext: {
98+
matches: [{ route: { path: '' } }, { route: { path: 'dashboard' } }, { route: { index: true } }],
99+
},
100+
} as any;
101+
await wrappedHandler(
102+
new Request('https://nacho.queso/dashboard'),
103+
200,
104+
new Headers(),
105+
nestedIndexContext,
106+
{} as any,
107+
);
108+
109+
expect(mockRootSpan.setAttributes).toHaveBeenLastCalledWith({
110+
[HTTP_ROUTE]: '/dashboard',
111+
[SENTRY_SEGMENT_NAME_SOURCE]: 'route',
112+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.request_handler',
113+
});
114+
});
115+
77116
test('should not set span attributes when parameterized path does not exist', async () => {
78117
const mockActiveSpan = {};
79118
const mockRootSpan = { setAttributes: vi.fn() };

0 commit comments

Comments
 (0)