Skip to content

Commit 4ee07cd

Browse files
committed
Address reviews further
1 parent 3084371 commit 4ee07cd

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
@@ -87,7 +87,7 @@ test('Creates a navigation transaction inside a lazy route', async ({ page }) =>
8787
});
8888

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

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

101109
// Navigate to another lazy route first
@@ -115,14 +123,6 @@ test('Creates navigation transactions between two different lazy routes', async
115123
expect(firstEvent.contexts?.trace?.op).toBe('navigation');
116124

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

256256
// Go to root page
257257
await page.goto('/');
258-
page.waitForTimeout(1000);
258+
await page.waitForTimeout(1000);
259259

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

342+
// Set up transaction listeners for both navigations
342343
const firstNavigationPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
343344
return (
344345
!!transactionEvent?.transaction &&
@@ -347,6 +348,14 @@ test('Allows legitimate POP navigation (back/forward) after pageload completes',
347348
);
348349
});
349350

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

352361
const slowLoadingContent = page.locator('id=slow-loading-content');
@@ -359,14 +368,6 @@ test('Allows legitimate POP navigation (back/forward) after pageload completes',
359368

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

372373
// 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)