Skip to content

Commit ef4f210

Browse files
Lms24tannerlinsleymydea
authored
fix(v8/react): From location can be undefined in Tanstack Router Instrumentation (#15237)
backport of #15235 and #15241 --------- Co-authored-by: Tanner Linsley <[email protected]> Co-authored-by: Francesco Novy <[email protected]>
1 parent 4df3759 commit ef4f210

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

packages/react/src/tanstackrouter.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ export function tanstackRouterBrowserTracingIntegration(
6464
if (instrumentNavigation) {
6565
// The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected
6666
castRouterInstance.subscribe('onBeforeNavigate', onBeforeNavigateArgs => {
67+
const fromLocationState = onBeforeNavigateArgs.fromLocation && onBeforeNavigateArgs.fromLocation.state;
6768
// onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by comparing the states of the to and from arguments.
68-
if (onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state) {
69+
if (onBeforeNavigateArgs.toLocation.state === fromLocationState) {
6970
return;
7071
}
7172

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface VendoredTanstackRouter {
4646
eventType: 'onResolved' | 'onBeforeNavigate',
4747
callback: (stateUpdate: {
4848
toLocation: VendoredTanstackRouterLocation;
49-
fromLocation: VendoredTanstackRouterLocation;
49+
fromLocation?: VendoredTanstackRouterLocation;
5050
}) => void,
5151
): () => void;
5252
}

0 commit comments

Comments
 (0)