fix(vue): Refresh pageload URL attrs on TanStack onResolved#22140
Open
Lms24 wants to merge 1 commit into
Open
Conversation
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>
e0de32c to
dc4941c
Compare
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); | ||
| }); | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pageload
onResolvedonly refreshed URL attributes when the resolvedrouteIdchanged. Redirects landing on the same route template with different pathname or params left staleurl.path,url.full, and param attributes on the span.This PR always applies the resolved route match on pageload
onResolved, matching navigation behavior.