Skip to content

Commit 67bb292

Browse files
fix(react): Tanstack Router integration matchRoutes signature changed
1 parent 72751da commit 67bb292

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

packages/react/src/tanstackrouter.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77

88
import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/browser';
99
import type { Integration } from '@sentry/types';
10-
import type { VendoredTanstackRouter, VendoredTanstackRouterRouteMatch } from './vendor/tanstackrouter-types';
10+
import type {
11+
VendoredTanstackRouter,
12+
VendoredTanstackRouterLocation,
13+
VendoredTanstackRouterRouteMatch,
14+
} from './vendor/tanstackrouter-types';
1115

1216
/**
1317
* A custom browser tracing integration for TanStack Router.
@@ -40,8 +44,10 @@ export function tanstackRouterBrowserTracingIntegration(
4044
const initialWindowLocation = WINDOW.location;
4145
if (instrumentPageLoad && initialWindowLocation) {
4246
const matchedRoutes = castRouterInstance.matchRoutes(
43-
initialWindowLocation.pathname,
44-
initialWindowLocation.search,
47+
{
48+
pathname: initialWindowLocation.pathname,
49+
search: castRouterInstance.options.parseSearch(initialWindowLocation.search),
50+
} as VendoredTanstackRouterLocation,
4551
{ preload: false, throwOnError: false },
4652
);
4753

@@ -66,11 +72,10 @@ export function tanstackRouterBrowserTracingIntegration(
6672
return;
6773
}
6874

69-
const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
70-
onBeforeNavigateArgs.toLocation.pathname,
71-
onBeforeNavigateArgs.toLocation.search,
72-
{ preload: false, throwOnError: false },
73-
);
75+
const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onBeforeNavigateArgs.toLocation, {
76+
preload: false,
77+
throwOnError: false,
78+
});
7479

7580
const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
7681

@@ -88,11 +93,10 @@ export function tanstackRouterBrowserTracingIntegration(
8893
const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => {
8994
unsubscribeOnResolved();
9095
if (navigationSpan) {
91-
const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(
92-
onResolvedArgs.toLocation.pathname,
93-
onResolvedArgs.toLocation.search,
94-
{ preload: false, throwOnError: false },
95-
);
96+
const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onResolvedArgs.toLocation, {
97+
preload: false,
98+
throwOnError: false,
99+
});
96100

97101
const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1];
98102

packages/react/src/vendor/tanstackrouter-types.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ SOFTWARE.
2929
export interface VendoredTanstackRouter {
3030
history: VendoredTanstackRouterHistory;
3131
state: VendoredTanstackRouterState;
32+
options: {
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
parseSearch: (search: string) => Record<string, any>;
35+
};
3236
matchRoutes: (
33-
pathname: string,
34-
// eslint-disable-next-line @typescript-eslint/ban-types
35-
locationSearch: {},
36-
opts?: {
37-
preload?: boolean;
38-
throwOnError?: boolean;
39-
},
37+
location: VendoredTanstackRouterLocation,
38+
opts?: { preload?: boolean; throwOnError?: boolean },
4039
) => Array<VendoredTanstackRouterRouteMatch>;
4140
subscribe(
4241
eventType: 'onResolved' | 'onBeforeNavigate',
@@ -47,7 +46,7 @@ export interface VendoredTanstackRouter {
4746
): () => void;
4847
}
4948

50-
interface VendoredTanstackRouterLocation {
49+
export interface VendoredTanstackRouterLocation {
5150
pathname: string;
5251
// eslint-disable-next-line @typescript-eslint/ban-types
5352
search: {};

0 commit comments

Comments
 (0)