Skip to content

Commit 5dcaebe

Browse files
Strip test query params from URL before Next.js hydration
1 parent d8870fe commit 5dcaebe

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

test/apps/nextjs/instrumentation-client.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ if (config && !datadogRum.getInitConfiguration()) {
1010
if (context) {
1111
datadogRum.setGlobalContext(JSON.parse(context))
1212
}
13+
14+
// Strip test-only query params from the URL so Next.js's segment cache
15+
// doesn't store them as the canonical URL for this route.
16+
const url = new URL(window.location.href)
17+
url.searchParams.delete('rum-config')
18+
url.searchParams.delete('rum-context')
19+
window.history.replaceState(window.history.state, '', url.toString())
1320
}
1421

1522
export { onRouterTransitionStart } from '@datadog/browser-rum-nextjs'

test/e2e/scenario/plugins/basePluginRouterTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function runBasePluginRouterTests(configs: RouterPluginTestConfig[]) {
6161
expect(guidesView).toBeDefined()
6262
expect(guidesView?.view.loading_type).toBe('route_change')
6363
expect(guidesView?.view.url).toContain('/guides/123')
64-
expect(guidesView?.view.referrer).toBe(baseUrl)
64+
expect(guidesView?.view.referrer).toBe(`${baseOrigin}${homeViewName}`)
6565

6666
const userView = viewEvents.find((e) => e.view.name === `${viewPrefix}${userRouteName}`)
6767
expect(userView).toBeDefined()

0 commit comments

Comments
 (0)