Skip to content

Commit fb2899c

Browse files
committed
Address reviews further
1 parent e4920d4 commit fb2899c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/tests/transactions.test.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('Creates a navigation transaction inside a lazy route', async ({ page }) =>
8585
});
8686

8787
test('Creates navigation transactions between two different lazy routes', async ({ page }) => {
88-
// First, navigate to the "another-lazy" route
88+
// Set up transaction listeners for both navigations
8989
const firstTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
9090
return (
9191
!!transactionEvent?.transaction &&
@@ -94,6 +94,14 @@ test('Creates navigation transactions between two different lazy routes', async
9494
);
9595
});
9696

97+
const secondTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
98+
return (
99+
!!transactionEvent?.transaction &&
100+
transactionEvent.contexts?.trace?.op === 'navigation' &&
101+
transactionEvent.transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
102+
);
103+
});
104+
97105
await page.goto('/');
98106

99107
// Navigate to another lazy route first
@@ -113,14 +121,6 @@ test('Creates navigation transactions between two different lazy routes', async
113121
expect(firstEvent.contexts?.trace?.op).toBe('navigation');
114122

115123
// Now navigate from the first lazy route to the second lazy route
116-
const secondTransactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
117-
return (
118-
!!transactionEvent?.transaction &&
119-
transactionEvent.contexts?.trace?.op === 'navigation' &&
120-
transactionEvent.transaction === '/lazy/inner/:id/:anotherId/:someAnotherId'
121-
);
122-
});
123-
124124
// Click the navigation link from within the first lazy route to the second lazy route
125125
const navigationToInnerFromDeep = page.locator('id=navigate-to-inner-from-deep');
126126
await expect(navigationToInnerFromDeep).toBeVisible();
@@ -253,7 +253,7 @@ test('Does not send any duplicate navigation transaction names browsing between
253253

254254
// Go to root page
255255
await page.goto('/');
256-
page.waitForTimeout(1000);
256+
await page.waitForTimeout(1000);
257257

258258
// Navigate to inner lazy route
259259
const navigationToInner = page.locator('id=navigation');
@@ -337,6 +337,7 @@ test('Allows legitimate POP navigation (back/forward) after pageload completes',
337337
const navigationToLongRunning = page.locator('id=navigation-to-long-running');
338338
await expect(navigationToLongRunning).toBeVisible();
339339

340+
// Set up transaction listeners for both navigations
340341
const firstNavigationPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
341342
return (
342343
!!transactionEvent?.transaction &&
@@ -345,6 +346,14 @@ test('Allows legitimate POP navigation (back/forward) after pageload completes',
345346
);
346347
});
347348

349+
const backNavigationPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
350+
return (
351+
!!transactionEvent?.transaction &&
352+
transactionEvent.contexts?.trace?.op === 'navigation' &&
353+
transactionEvent.transaction === '/'
354+
);
355+
});
356+
348357
await navigationToLongRunning.click();
349358

350359
const slowLoadingContent = page.locator('id=slow-loading-content');
@@ -357,14 +366,6 @@ test('Allows legitimate POP navigation (back/forward) after pageload completes',
357366

358367
// Now navigate back using browser back button (POP event)
359368
// This should create a navigation transaction since pageload is complete
360-
const backNavigationPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
361-
return (
362-
!!transactionEvent?.transaction &&
363-
transactionEvent.contexts?.trace?.op === 'navigation' &&
364-
transactionEvent.transaction === '/'
365-
);
366-
});
367-
368369
await page.goBack();
369370

370371
// Verify we're back at home

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet<Client>();
5454

5555
/**
5656
* Tracks last navigation per client to prevent duplicate spans in cross-usage scenarios.
57-
* Entry persists until next different navigation, handling delayed wrapper execution.
57+
* Entry persists until the navigation span ends, allowing cross-usage detection during delayed wrapper execution.
5858
*/
5959
const LAST_NAVIGATION_PER_CLIENT = new WeakMap<Client, string>();
6060

@@ -628,7 +628,9 @@ function tryUpdateSpanName(
628628
newName: string,
629629
newSource: string,
630630
): void {
631-
const isNewNameParameterized = newName !== currentSpanName && newName.includes(':');
631+
// Check if the new name contains React Router parameter syntax (/:param/)
632+
const isReactRouterParam = /\/:[a-zA-Z0-9_]+/.test(newName);
633+
const isNewNameParameterized = newName !== currentSpanName && isReactRouterParam;
632634
if (isNewNameParameterized) {
633635
activeSpan.updateName(newName);
634636
activeSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, newSource as 'route' | 'url' | 'custom');

0 commit comments

Comments
 (0)