Skip to content

Commit bf87914

Browse files
committed
fix: Check for existence before reporting pageload
1 parent 2ad7ca1 commit bf87914

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/react/src/tanstackrouter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ 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-
// 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) {
67+
// onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by:
68+
// 1. Checking if there's no fromLocation (initial pageload)
69+
// 2. Comparing the states of the to and from arguments
70+
if (
71+
!onBeforeNavigateArgs.fromLocation ||
72+
onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state
73+
) {
6974
return;
7075
}
7176

0 commit comments

Comments
 (0)