Skip to content

Commit

Permalink
fix(nextjs): Strip query params from transaction names of navigations…
Browse files Browse the repository at this point in the history
… to unknown routes (#8278)

Fix a possible scenario in which transaction names can have query params, 
namely a navigation to an unknown route.
  • Loading branch information
Lms24 authored Jun 2, 2023
1 parent 3771d05 commit 1df2367
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/nextjs/src/client/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -152,7 +153,7 @@ export function nextRouterInstrumentation(
transactionName = matchedRoute;
transactionSource = 'route';
} else {
transactionName = navigationTarget;
transactionName = strippedNavigationTarget;
transactionSource = 'url';
}

Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/performance/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1df2367

Please sign in to comment.