Skip to content

Commit 651e8e0

Browse files
committed
Undo change to global.location
1 parent 22a0f83 commit 651e8e0

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

packages/nextjs/src/performance/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function nextRouterInstrumentation(
111111
if (startTransactionOnPageLoad) {
112112
const { route, traceParentData, baggage, params } = extractNextDataTagInformation();
113113

114-
prevTransactionName = route || global.document.location.pathname;
114+
prevTransactionName = route || global.location.pathname;
115115
const source = route ? 'route' : 'url';
116116

117117
activeTransaction = startTransactionCb({

packages/nextjs/test/index.client.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ const logWarn = jest.spyOn(logger, 'warn');
2020
// Set up JSDom - needed for page load instrumentation
2121
const dom = new JSDOM(undefined, { url: 'https://example.com/' });
2222
Object.defineProperty(global, 'document', { value: dom.window.document, writable: true });
23+
Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true });
2324

2425
const originalGlobalDocument = getGlobalObject<Window>().document;
26+
const originalGlobalLocation = getGlobalObject<Window>().location;
2527
afterAll(() => {
2628
// Clean up JSDom
27-
Object.defineProperty(global, 'document', {
28-
value: originalGlobalDocument,
29-
});
29+
Object.defineProperty(global, 'document', { value: originalGlobalDocument });
30+
Object.defineProperty(global, 'location', { value: originalGlobalLocation });
3031
});
3132

3233
describe('Client init()', () => {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('client', () => {
3131

3232
describe('nextRouterInstrumentation', () => {
3333
const originalGlobalDocument = getGlobalObject<Window>().document;
34+
const originalGlobalLocation = getGlobalObject<Window>().location;
3435

3536
function setUpNextPage(pageProperties: {
3637
url: string;
@@ -61,11 +62,13 @@ describe('client', () => {
6162
);
6263

6364
Object.defineProperty(global, 'document', { value: dom.window.document, writable: true });
65+
Object.defineProperty(global, 'location', { value: dom.window.document.location, writable: true });
6466
}
6567

6668
afterEach(() => {
6769
// Clean up JSDom
6870
Object.defineProperty(global, 'document', { value: originalGlobalDocument });
71+
Object.defineProperty(global, 'location', { value: originalGlobalLocation });
6972
});
7073

7174
it('waits for Router.ready()', () => {

0 commit comments

Comments
 (0)