Skip to content

Commit 8ae6a96

Browse files
committed
Address remaining PR review comments
1 parent 853d062 commit 8ae6a96

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,12 @@ function wrapPatchRoutesOnNavigation(
731731
(args as any).patch = (routeId: string, children: RouteObject[]) => {
732732
addRoutesToAllRoutes(children);
733733
const currentActiveRootSpan = getActiveRootSpan();
734-
if (currentActiveRootSpan && (spanToJSON(currentActiveRootSpan) as { op?: string }).op === 'navigation') {
734+
// Only update if we have a valid targetPath (patchRoutesOnNavigation can be called without path)
735+
if (
736+
targetPath &&
737+
currentActiveRootSpan &&
738+
(spanToJSON(currentActiveRootSpan) as { op?: string }).op === 'navigation'
739+
) {
735740
updateNavigationSpan(
736741
currentActiveRootSpan,
737742
{ pathname: targetPath, search: '', hash: '', state: null, key: 'default' },

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function clearNavigationContext(token: object): void {
4848
/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */
4949
export function getNavigationContext(): NavigationContext | null {
5050
const length = _navigationContextStack.length;
51+
// The `?? null` converts undefined (from array access) to null to match return type
5152
return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;
5253
}
5354

0 commit comments

Comments
 (0)