Skip to content

Commit 1df2367

Browse files
authored
fix(nextjs): Strip query params from transaction names of navigations to unknown routes (#8278)
Fix a possible scenario in which transaction names can have query params, namely a navigation to an unknown route.
1 parent 3771d05 commit 1df2367

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/nextjs/src/client/performance.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ export function nextRouterInstrumentation(
143143

144144
if (startTransactionOnLocationChange) {
145145
Router.events.on('routeChangeStart', (navigationTarget: string) => {
146-
const matchedRoute = getNextRouteFromPathname(stripUrlQueryAndFragment(navigationTarget));
146+
const strippedNavigationTarget = stripUrlQueryAndFragment(navigationTarget);
147+
const matchedRoute = getNextRouteFromPathname(strippedNavigationTarget);
147148

148149
let transactionName: string;
149150
let transactionSource: TransactionSource;
@@ -152,7 +153,7 @@ export function nextRouterInstrumentation(
152153
transactionName = matchedRoute;
153154
transactionSource = 'route';
154155
} else {
155-
transactionName = navigationTarget;
156+
transactionName = strippedNavigationTarget;
156157
transactionSource = 'url';
157158
}
158159

packages/nextjs/test/performance/client.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ describe('nextRouterInstrumentation', () => {
231231
['/news', '/news', 'route'],
232232
['/news/', '/news', 'route'],
233233
['/some-route-that-is-not-defined-12332', '/some-route-that-is-not-defined-12332', 'url'], // unknown route
234+
['/some-route-that-is-not-defined-12332?q=42', '/some-route-that-is-not-defined-12332', 'url'], // unknown route w/ query param
234235
['/posts/42', '/posts/[id]', 'route'],
235236
['/posts/42/', '/posts/[id]', 'route'],
236237
['/posts/42?someParam=1', '/posts/[id]', 'route'], // query params are ignored

0 commit comments

Comments
 (0)