From 67bb292ed90ee3a2f5eb5e18a1237f83b66fcef4 Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Sat, 16 Nov 2024 16:19:40 -0500 Subject: [PATCH 1/2] fix(react): Tanstack Router integration matchRoutes signature changed --- packages/react/src/tanstackrouter.ts | 30 +++++++++++-------- .../react/src/vendor/tanstackrouter-types.ts | 15 +++++----- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/react/src/tanstackrouter.ts b/packages/react/src/tanstackrouter.ts index 2efefba49e31..570cc7043e37 100644 --- a/packages/react/src/tanstackrouter.ts +++ b/packages/react/src/tanstackrouter.ts @@ -7,7 +7,11 @@ import { import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/browser'; import type { Integration } from '@sentry/types'; -import type { VendoredTanstackRouter, VendoredTanstackRouterRouteMatch } from './vendor/tanstackrouter-types'; +import type { + VendoredTanstackRouter, + VendoredTanstackRouterLocation, + VendoredTanstackRouterRouteMatch, +} from './vendor/tanstackrouter-types'; /** * A custom browser tracing integration for TanStack Router. @@ -40,8 +44,10 @@ export function tanstackRouterBrowserTracingIntegration( const initialWindowLocation = WINDOW.location; if (instrumentPageLoad && initialWindowLocation) { const matchedRoutes = castRouterInstance.matchRoutes( - initialWindowLocation.pathname, - initialWindowLocation.search, + { + pathname: initialWindowLocation.pathname, + search: castRouterInstance.options.parseSearch(initialWindowLocation.search), + } as VendoredTanstackRouterLocation, { preload: false, throwOnError: false }, ); @@ -66,11 +72,10 @@ export function tanstackRouterBrowserTracingIntegration( return; } - const onResolvedMatchedRoutes = castRouterInstance.matchRoutes( - onBeforeNavigateArgs.toLocation.pathname, - onBeforeNavigateArgs.toLocation.search, - { preload: false, throwOnError: false }, - ); + const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onBeforeNavigateArgs.toLocation, { + preload: false, + throwOnError: false, + }); const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1]; @@ -88,11 +93,10 @@ export function tanstackRouterBrowserTracingIntegration( const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => { unsubscribeOnResolved(); if (navigationSpan) { - const onResolvedMatchedRoutes = castRouterInstance.matchRoutes( - onResolvedArgs.toLocation.pathname, - onResolvedArgs.toLocation.search, - { preload: false, throwOnError: false }, - ); + const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onResolvedArgs.toLocation, { + preload: false, + throwOnError: false, + }); const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1]; diff --git a/packages/react/src/vendor/tanstackrouter-types.ts b/packages/react/src/vendor/tanstackrouter-types.ts index 99a4510228a3..a7bc1963418d 100644 --- a/packages/react/src/vendor/tanstackrouter-types.ts +++ b/packages/react/src/vendor/tanstackrouter-types.ts @@ -29,14 +29,13 @@ SOFTWARE. export interface VendoredTanstackRouter { history: VendoredTanstackRouterHistory; state: VendoredTanstackRouterState; + options: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + parseSearch: (search: string) => Record; + }; matchRoutes: ( - pathname: string, - // eslint-disable-next-line @typescript-eslint/ban-types - locationSearch: {}, - opts?: { - preload?: boolean; - throwOnError?: boolean; - }, + location: VendoredTanstackRouterLocation, + opts?: { preload?: boolean; throwOnError?: boolean }, ) => Array; subscribe( eventType: 'onResolved' | 'onBeforeNavigate', @@ -47,7 +46,7 @@ export interface VendoredTanstackRouter { ): () => void; } -interface VendoredTanstackRouterLocation { +export interface VendoredTanstackRouterLocation { pathname: string; // eslint-disable-next-line @typescript-eslint/ban-types search: {}; From 6d8a543da1d8c5aef98eba3c32f756873c2d8ac6 Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Thu, 21 Nov 2024 10:23:10 -0500 Subject: [PATCH 2/2] fix(react): revert matchRoutes API changes --- packages/react/src/tanstackrouter.ts | 30 ++++++++----------- .../react/src/vendor/tanstackrouter-types.ts | 11 +++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/react/src/tanstackrouter.ts b/packages/react/src/tanstackrouter.ts index 570cc7043e37..59cb059bfb2d 100644 --- a/packages/react/src/tanstackrouter.ts +++ b/packages/react/src/tanstackrouter.ts @@ -7,11 +7,7 @@ import { import { browserTracingIntegration as originalBrowserTracingIntegration } from '@sentry/browser'; import type { Integration } from '@sentry/types'; -import type { - VendoredTanstackRouter, - VendoredTanstackRouterLocation, - VendoredTanstackRouterRouteMatch, -} from './vendor/tanstackrouter-types'; +import type { VendoredTanstackRouter, VendoredTanstackRouterRouteMatch } from './vendor/tanstackrouter-types'; /** * A custom browser tracing integration for TanStack Router. @@ -44,10 +40,8 @@ export function tanstackRouterBrowserTracingIntegration( const initialWindowLocation = WINDOW.location; if (instrumentPageLoad && initialWindowLocation) { const matchedRoutes = castRouterInstance.matchRoutes( - { - pathname: initialWindowLocation.pathname, - search: castRouterInstance.options.parseSearch(initialWindowLocation.search), - } as VendoredTanstackRouterLocation, + initialWindowLocation.pathname, + castRouterInstance.options.parseSearch(initialWindowLocation.search), { preload: false, throwOnError: false }, ); @@ -72,10 +66,11 @@ export function tanstackRouterBrowserTracingIntegration( return; } - const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onBeforeNavigateArgs.toLocation, { - preload: false, - throwOnError: false, - }); + const onResolvedMatchedRoutes = castRouterInstance.matchRoutes( + onBeforeNavigateArgs.toLocation.pathname, + onBeforeNavigateArgs.toLocation.search, + { preload: false, throwOnError: false }, + ); const onBeforeNavigateLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1]; @@ -93,10 +88,11 @@ export function tanstackRouterBrowserTracingIntegration( const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => { unsubscribeOnResolved(); if (navigationSpan) { - const onResolvedMatchedRoutes = castRouterInstance.matchRoutes(onResolvedArgs.toLocation, { - preload: false, - throwOnError: false, - }); + const onResolvedMatchedRoutes = castRouterInstance.matchRoutes( + onResolvedArgs.toLocation.pathname, + onResolvedArgs.toLocation.search, + { preload: false, throwOnError: false }, + ); const onResolvedLastMatch = onResolvedMatchedRoutes[onResolvedMatchedRoutes.length - 1]; diff --git a/packages/react/src/vendor/tanstackrouter-types.ts b/packages/react/src/vendor/tanstackrouter-types.ts index a7bc1963418d..e5eeba71aa87 100644 --- a/packages/react/src/vendor/tanstackrouter-types.ts +++ b/packages/react/src/vendor/tanstackrouter-types.ts @@ -34,8 +34,13 @@ export interface VendoredTanstackRouter { parseSearch: (search: string) => Record; }; matchRoutes: ( - location: VendoredTanstackRouterLocation, - opts?: { preload?: boolean; throwOnError?: boolean }, + pathname: string, + // eslint-disable-next-line @typescript-eslint/ban-types + locationSearch: {}, + opts?: { + preload?: boolean; + throwOnError?: boolean; + }, ) => Array; subscribe( eventType: 'onResolved' | 'onBeforeNavigate', @@ -46,7 +51,7 @@ export interface VendoredTanstackRouter { ): () => void; } -export interface VendoredTanstackRouterLocation { +interface VendoredTanstackRouterLocation { pathname: string; // eslint-disable-next-line @typescript-eslint/ban-types search: {};