Skip to content

Commit 2f205ce

Browse files
committed
Update patch functions to use live global allRoutes Set for lazy route handling
1 parent 7c622f8 commit 2f205ce

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ function patchPageloadSpanEnd(
782782
location: Location,
783783
routes: RouteObject[],
784784
basename: string | undefined,
785-
allRoutes: RouteObject[] | undefined,
785+
_allRoutes: RouteObject[] | undefined,
786786
): void {
787787
const hasEndBeenPatched = (span as { __sentry_pageload_end_patched__?: boolean })?.__sentry_pageload_end_patched__;
788788

@@ -798,10 +798,12 @@ function patchPageloadSpanEnd(
798798
const currentSource = spanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
799799
if (currentSource !== 'route') {
800800
// Last chance to update the transaction name with the latest route info
801-
const branches = _matchRoutes(allRoutes || routes, location, basename) as unknown as RouteMatch[];
801+
// Use the live global allRoutes Set to include any lazy routes loaded after patching
802+
const currentAllRoutes = Array.from(allRoutes);
803+
const branches = _matchRoutes(currentAllRoutes || routes, location, basename) as unknown as RouteMatch[];
802804

803805
if (branches) {
804-
const [latestName, latestSource] = getTransactionNameAndSource(location, routes, branches, basename, allRoutes);
806+
const [latestName, latestSource] = getTransactionNameAndSource(location, routes, branches, basename, currentAllRoutes);
805807

806808
span.updateName(latestName);
807809
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, latestSource);
@@ -828,7 +830,7 @@ function patchNavigationSpanEnd(
828830
location: Location,
829831
routes: RouteObject[],
830832
basename: string | undefined,
831-
allRoutes: RouteObject[] | undefined,
833+
_allRoutes: RouteObject[] | undefined,
832834
): void {
833835
const hasEndBeenPatched = (span as { __sentry_navigation_end_patched__?: boolean })
834836
?.__sentry_navigation_end_patched__;
@@ -845,10 +847,12 @@ function patchNavigationSpanEnd(
845847
const currentSource = spanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
846848
if (currentSource !== 'route') {
847849
// Last chance to update the transaction name with the latest route info
848-
const branches = _matchRoutes(allRoutes || routes, location, basename) as unknown as RouteMatch[];
850+
// Use the live global allRoutes Set to include any lazy routes loaded after patching
851+
const currentAllRoutes = Array.from(allRoutes);
852+
const branches = _matchRoutes(currentAllRoutes || routes, location, basename) as unknown as RouteMatch[];
849853

850854
if (branches) {
851-
const [name, source] = resolveRouteNameAndSource(location, routes, allRoutes || routes, branches, basename);
855+
const [name, source] = resolveRouteNameAndSource(location, routes, currentAllRoutes, branches, basename);
852856

853857
// Only update if we have a valid name and the span hasn't finished
854858
if (name && !spanJson.timestamp) {

0 commit comments

Comments
 (0)