66 browserTracingIntegration ,
77 startBrowserTracingNavigationSpan ,
88 startBrowserTracingPageLoadSpan ,
9- WINDOW ,
109} from '@sentry/browser' ;
1110import type { Client , Integration , Span , TransactionSource } from '@sentry/core' ;
1211import {
@@ -42,6 +41,7 @@ import type {
4241} from '../types' ;
4342import { checkRouteForAsyncHandler , updateNavigationSpanWithLazyRoutes } from './lazy-routes' ;
4443import {
44+ getGlobalLocation ,
4545 getNormalizedName ,
4646 initializeRouterUtils ,
4747 locationIsInsideDescendantRoute ,
@@ -59,31 +59,6 @@ let _enableAsyncRouteHandlers: boolean = false;
5959
6060const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet < Client > ( ) ;
6161
62- /**
63- * Gets the current location from the window object in browser environments.
64- * Returns undefined if window is not available.
65- */
66- function getGlobalLocation ( ) : Location | undefined {
67- if ( typeof WINDOW !== 'undefined' ) {
68- const globalLocation = WINDOW . location ;
69- if ( globalLocation ) {
70- return { pathname : globalLocation . pathname } ;
71- }
72- }
73- return undefined ;
74- }
75-
76- /**
77- * Gets the pathname from the window object in browser environments.
78- * Returns undefined if window is not available.
79- */
80- function getGlobalPathname ( ) : string | undefined {
81- if ( typeof WINDOW !== 'undefined' ) {
82- return WINDOW . location ?. pathname ;
83- }
84- return undefined ;
85- }
86-
8762export interface ReactRouterOptions {
8863 useEffect : UseEffect ;
8964 useLocation : UseLocation ;
@@ -213,7 +188,7 @@ function wrapPatchRoutesOnNavigation(
213188 if ( activeRootSpan && ( spanToJSON ( activeRootSpan ) as { op ?: string } ) . op === 'navigation' ) {
214189 // For memory routers, we don't have a reliable way to get the current pathname
215190 // without accessing window.location, so we'll use targetPath for both cases
216- const pathname = targetPath || ( isMemoryRouter ? getGlobalPathname ( ) : undefined ) ;
191+ const pathname = targetPath || ( isMemoryRouter ? getGlobalLocation ( ) ?. pathname : undefined ) ;
217192 if ( pathname ) {
218193 updateNavigationSpanWithLazyRoutes (
219194 activeRootSpan ,
@@ -446,7 +421,7 @@ export function createReactRouterV6CompatibleTracingIntegration(
446421 afterAllSetup ( client ) {
447422 integration . afterAllSetup ( client ) ;
448423
449- const initPathName = getGlobalPathname ( ) ;
424+ const initPathName = getGlobalLocation ( ) ?. pathname ;
450425 if ( instrumentPageLoad && initPathName ) {
451426 startBrowserTracingPageLoadSpan ( client , {
452427 name : initPathName ,
0 commit comments