You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(react): Prevent navigation span leaks for consecutive navigations (#18098)
Fixes an issue where consecutive navigations to different routes fail to
create separate navigation spans, causing span leaks and missing
transaction data.
This came up in a React Router v6/v7 application where the pageload /
navigation transactions take longer and there is a high `finalTimeout`
set in config. When users navigate between different routes (e.g.,
`/users/:id` → `/projects/:projectId` → `/settings`). The SDK was
incorrectly preventing new navigation spans from being created whenever
an ongoing navigation span was active, regardless of whether the
navigation was to a different route. This resulted in only the first
navigation being tracked, with subsequent navigations being silently
ignored. Also, the spans that needed to be a part of the subsequent
navigation were recorded as a part of the previous one.
The root cause was the `if (!isAlreadyInNavigationSpan)` check that we
used to prevent cross-usage scenarios (multiple wrappers instrumenting
the same navigation), which incorrectly blocked legitimate consecutive
navigations to different routes.
So, this fix changes the logic to check both navigation span state and
the route name: `isSpanForSameRoute = isAlreadyInNavigationSpan &&
spanJson?.description === name`. This allows consecutive navigations to
different routes while preventing duplicate spans for the same route.
Also added tracking using `LAST_NAVIGATION_PER_CLIENT`. When multiple
wrappers (e.g., `wrapCreateBrowserRouter` + `wrapUseRoutes`) instrument
the same application, they may each trigger span creation for the same
navigation event. We store the navigation key
`${location.pathname}${location.search}${location.hash}` while the span
is active and clear it when that span ends.
If the same navigation key shows up again before the original span
finishes, the second wrapper updates that span’s name if it has better
parameterization instead of creating a duplicate, which keeps
cross-usage covered.
0 commit comments