Skip to content

Commit 1431408

Browse files
Apply suggestions from Copilot review
Co-authored-by: Copilot <[email protected]>
1 parent 8507984 commit 1431408

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ const allRoutes = new Set<RouteObject>();
112112
/**
113113
* Processes resolved routes by adding them to allRoutes and checking for nested async handlers.
114114
*/
115-
export function processResolvedRoutes(
116-
resolvedRoutes: RouteObject[],
117-
parentRoute?: RouteObject,
118-
currentLocation?: Location,
115+
currentLocation: Location | null = null,
119116
): void {
120117
resolvedRoutes.forEach(child => {
121118
allRoutes.add(child);
@@ -137,11 +134,7 @@ export function processResolvedRoutes(
137134

138135
// Try to use the provided location first, then fall back to global window location if needed
139136
let location = currentLocation;
140-
if (!location) {
141-
if (typeof WINDOW !== 'undefined') {
142-
const globalLocation = WINDOW.location;
143-
if (globalLocation) {
144-
location = { pathname: globalLocation.pathname };
137+
location = createDefaultLocation(globalLocation.pathname);
145138
}
146139
}
147140
}
@@ -553,9 +546,8 @@ function wrapPatchRoutesOnNavigation(
553546
// Update navigation span after routes are patched
554547
const activeRootSpan = getActiveRootSpan();
555548
if (activeRootSpan && (spanToJSON(activeRootSpan) as { op?: string }).op === 'navigation') {
556-
// For memory routers, we don't have a reliable way to get the current pathname
557-
// without accessing window.location, so we'll use targetPath for both cases
558-
const pathname = targetPath || (isMemoryRouter ? WINDOW.location?.pathname : undefined);
549+
// For memory routers, we should not access window.location; use targetPath only
550+
const pathname = isMemoryRouter ? targetPath : targetPath || WINDOW.location?.pathname;
559551
if (pathname) {
560552
updateNavigationSpan(
561553
activeRootSpan,

packages/react/src/reactrouter-compat-utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ export function getNormalizedName(
252252
}
253253

254254
const fallbackTransactionName = _stripBasename
255-
? stripBasenameFromPathname(location.pathname, basename)
256-
: location.pathname;
255+
? stripBasenameFromPathname(location.pathname ?? '', basename)
256+
: location.pathname ?? '';
257257

258258
return [fallbackTransactionName, 'url'];
259259
}

0 commit comments

Comments
 (0)