From 5e929e9a9166bda3a5e379c91569f32d6fafd840 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 2 Jun 2023 09:51:43 +0200 Subject: [PATCH] fix(nextjs): Strip query params from navigation transactions of unknown routes --- packages/nextjs/src/client/performance.ts | 5 +++-- packages/nextjs/test/performance/client.test.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/src/client/performance.ts b/packages/nextjs/src/client/performance.ts index 2212092d5045..0dd0b109408f 100644 --- a/packages/nextjs/src/client/performance.ts +++ b/packages/nextjs/src/client/performance.ts @@ -143,7 +143,8 @@ export function nextRouterInstrumentation( if (startTransactionOnLocationChange) { Router.events.on('routeChangeStart', (navigationTarget: string) => { - const matchedRoute = getNextRouteFromPathname(stripUrlQueryAndFragment(navigationTarget)); + const strippedNavigationTarget = stripUrlQueryAndFragment(navigationTarget); + const matchedRoute = getNextRouteFromPathname(strippedNavigationTarget); let transactionName: string; let transactionSource: TransactionSource; @@ -152,7 +153,7 @@ export function nextRouterInstrumentation( transactionName = matchedRoute; transactionSource = 'route'; } else { - transactionName = navigationTarget; + transactionName = strippedNavigationTarget; transactionSource = 'url'; } diff --git a/packages/nextjs/test/performance/client.test.ts b/packages/nextjs/test/performance/client.test.ts index 0b3ae0e7437e..cc0f212cbf18 100644 --- a/packages/nextjs/test/performance/client.test.ts +++ b/packages/nextjs/test/performance/client.test.ts @@ -231,6 +231,7 @@ describe('nextRouterInstrumentation', () => { ['/news', '/news', 'route'], ['/news/', '/news', 'route'], ['/some-route-that-is-not-defined-12332', '/some-route-that-is-not-defined-12332', 'url'], // unknown route + ['/some-route-that-is-not-defined-12332?q=42', '/some-route-that-is-not-defined-12332', 'url'], // unknown route w/ query param ['/posts/42', '/posts/[id]', 'route'], ['/posts/42/', '/posts/[id]', 'route'], ['/posts/42?someParam=1', '/posts/[id]', 'route'], // query params are ignored