Skip to content

Commit c54e779

Browse files
committed
refactor updatePageloadTransaction
1 parent 93f8599 commit c54e779

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

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

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,12 @@ export function processResolvedRoutes(
149149
if (location) {
150150
if (spanOp === 'pageload') {
151151
// Re-run the pageload transaction update with the newly loaded routes
152-
updatePageloadTransaction(
152+
updatePageloadTransaction({
153153
activeRootSpan,
154-
{ pathname: location.pathname },
155-
Array.from(allRoutes),
156-
undefined,
157-
undefined,
158-
Array.from(allRoutes),
159-
);
154+
location: { pathname: location.pathname },
155+
routes: Array.from(allRoutes),
156+
allRoutes: Array.from(allRoutes),
157+
});
160158
} else if (spanOp === 'navigation') {
161159
// For navigation spans, update the name with the newly loaded routes
162160
updateNavigationSpan(activeRootSpan, location, Array.from(allRoutes), false, _matchRoutes);
@@ -253,14 +251,13 @@ export function createV6CompatibleWrapCreateBrowserRouter<
253251
// This is the earliest convenient time to update the transaction name.
254252
// Callbacks to `router.subscribe` are not called for the initial load.
255253
if (router.state.historyAction === 'POP' && activeRootSpan) {
256-
updatePageloadTransaction(
254+
updatePageloadTransaction({
257255
activeRootSpan,
258-
router.state.location,
256+
location: router.state.location,
259257
routes,
260-
undefined,
261258
basename,
262-
Array.from(allRoutes),
263-
);
259+
allRoutes: Array.from(allRoutes),
260+
});
264261
}
265262

266263
router.subscribe((state: RouterState) => {
@@ -358,7 +355,13 @@ export function createV6CompatibleWrapCreateMemoryRouter<
358355
: router.state.location;
359356

360357
if (router.state.historyAction === 'POP' && activeRootSpan) {
361-
updatePageloadTransaction(activeRootSpan, location, routes, undefined, basename, Array.from(allRoutes));
358+
updatePageloadTransaction({
359+
activeRootSpan,
360+
location,
361+
routes,
362+
basename,
363+
allRoutes: Array.from(allRoutes),
364+
});
362365
}
363366

364367
router.subscribe((state: RouterState) => {
@@ -475,14 +478,12 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
475478
if (isMountRenderPass.current) {
476479
addRoutesToAllRoutes(routes);
477480

478-
updatePageloadTransaction(
479-
getActiveRootSpan(),
480-
normalizedLocation,
481+
updatePageloadTransaction({
482+
activeRootSpan: getActiveRootSpan(),
483+
location: normalizedLocation,
481484
routes,
482-
undefined,
483-
undefined,
484-
Array.from(allRoutes),
485-
);
485+
allRoutes: Array.from(allRoutes),
486+
});
486487
isMountRenderPass.current = false;
487488
} else {
488489
handleNavigation({
@@ -647,14 +648,21 @@ function getChildRoutesRecursively(route: RouteObject, allRoutes: Set<RouteObjec
647648
return allRoutes;
648649
}
649650

650-
function updatePageloadTransaction(
651-
activeRootSpan: Span | undefined,
652-
location: Location,
653-
routes: RouteObject[],
654-
matches?: AgnosticDataRouteMatch,
655-
basename?: string,
656-
allRoutes?: RouteObject[],
657-
): void {
651+
function updatePageloadTransaction({
652+
activeRootSpan,
653+
location,
654+
routes,
655+
matches,
656+
basename,
657+
allRoutes,
658+
}: {
659+
activeRootSpan: Span | undefined;
660+
location: Location;
661+
routes: RouteObject[];
662+
matches?: AgnosticDataRouteMatch;
663+
basename?: string;
664+
allRoutes?: RouteObject[];
665+
}): void {
658666
const branches = Array.isArray(matches)
659667
? matches
660668
: (_matchRoutes(allRoutes || routes, location, basename) as unknown as RouteMatch[]);
@@ -710,7 +718,12 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
710718
if (isMountRenderPass.current) {
711719
addRoutesToAllRoutes(routes);
712720

713-
updatePageloadTransaction(getActiveRootSpan(), location, routes, undefined, undefined, Array.from(allRoutes));
721+
updatePageloadTransaction({
722+
activeRootSpan: getActiveRootSpan(),
723+
location,
724+
routes,
725+
allRoutes: Array.from(allRoutes),
726+
});
714727
isMountRenderPass.current = false;
715728
} else {
716729
handleNavigation({

0 commit comments

Comments
 (0)