Skip to content

fix(vue): Refresh pageload URL attrs on TanStack onResolved#22140

Open
Lms24 wants to merge 1 commit into
developfrom
fix/vue-tanstack-pageload-onresolved
Open

fix(vue): Refresh pageload URL attrs on TanStack onResolved#22140
Lms24 wants to merge 1 commit into
developfrom
fix/vue-tanstack-pageload-onresolved

Conversation

@Lms24

@Lms24 Lms24 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Pageload onResolved only refreshed URL attributes when the resolved routeId changed. Redirects landing on the same route template with different pathname or params left stale url.path, url.full, and param attributes on the span.

This PR always applies the resolved route match on pageload onResolved, matching navigation behavior.

Pageload onResolved only updated url.path, url.full, and param attributes
when the resolved routeId differed from the initial match. Redirects to the
same route template with different params left stale URL fields on the span.

Co-Authored-By: Cursor <cursoragent@cursor.com>
@Lms24 Lms24 force-pushed the fix/vue-tanstack-pageload-onresolved branch from e0de32c to dc4941c Compare July 9, 2026 14:02
@Lms24 Lms24 self-assigned this Jul 9, 2026
@Lms24 Lms24 marked this pull request as ready for review July 9, 2026 16:49
@Lms24 Lms24 requested a review from a team as a code owner July 9, 2026 16:49
@Lms24 Lms24 requested review from chargome, mydea and s1gr1d and removed request for a team July 9, 2026 16:49
Comment on lines 104 to 110
}
const { toLocation } = onResolvedArgs as TanstackRouterSubscribeArgs;
const resolvedMatch = resolveRouteMatch(toLocation.pathname, toLocation.search);
if (resolvedMatch && resolvedMatch.routeId !== routeMatch?.routeId) {
pageloadSpan.updateName(resolvedMatch.routeId);
pageloadSpan.setAttributes({
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
[URL_TEMPLATE]: resolvedMatch.routeId,
...locationToSpanUrlAttributes(router, toLocation),
...routeMatchToParamSpanAttributes(resolvedMatch),
});
}
applyRouteMatch(pageloadSpan, resolvedMatch, toLocation, toLocation.pathname);
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The onResolved handler for pageloads unconditionally calls applyRouteMatch, potentially corrupting the span's name and attributes if the route resolution returns undefined.
Severity: MEDIUM

Suggested Fix

Reintroduce a guard to ensure applyRouteMatch is only called when resolvedMatch is not undefined. This can be done by wrapping the call in an if (resolvedMatch) block, similar to the React implementation. This prevents the pageload span from being incorrectly updated when a route is not resolved during the onResolved event.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/vue/src/tanstackrouter.ts#L104-L110

Potential issue: The pull request removes a guard condition in the `onResolved` handler
for pageloads. Previously, the transaction span was updated only if `resolvedMatch` was
defined. Now, `applyRouteMatch` is called unconditionally. In a scenario where a route
is matched on initial load but the subsequent `onResolved` check does not find a
specific match (returning `undefined`), the `pageloadSpan` data is overwritten. This
changes the span name from the parameterized route (e.g., `/users/:id`) to the raw URL,
sets the source to `'url'`, and clears the `URL_TEMPLATE` attribute, resulting in a loss
of valuable transaction information.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant