-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(react): Patch spanEnd for potentially cancelled lazy-route transactions
#17962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a09c3a7 to
03e62e7
Compare
spanEnd for potentially cancelled lazy-route pageloadsspanEnd for potentially cancelled lazy-route transactions
03e62e7 to
7c622f8
Compare
size-limit report 📦
|
20d8466 to
3345b67
Compare
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
5ac0764 to
e7270bc
Compare
packages/react/src/reactrouter-compat-utils/instrumentation.tsx
Outdated
Show resolved
Hide resolved
| * Patches the span.end() method to update the transaction name one last time before the span is sent. | ||
| * This handles cases where the span is cancelled early (e.g., document.hidden) before lazy routes have finished loading. | ||
| */ | ||
| function patchSpanEnd( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have client.on("spanEnd"). Is it possible to use it here? Then it would be more transparent and aligned with the other implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's not usable in this case, as we need to update the span name/source right before it ends. Looks like client.on('spanEnd') runs when the span is not mutable anymore.
Fixes an issue where
pageloadandnavigationtransactions have incorrect (URL-based or wildcard-based) names when the span is cancelled early before lazy routes finish loading.This occurs when
document.hiddentriggers early span cancellation (e.g., user switches tabs during page load). In React Router applications with lazy routes, the parameterized route information may not be available yet when the span ends, resulting in transaction names like/user/123/edit(URL-based) or/projects/*/views/*(wildcard-based) instead of the correct parameterized route like/user/:id/editor/projects/:projectId/views/:viewId.This fix patches
span.end()to perform a final route resolution check before the span is sent, using the live globalallRoutesSet to capture any lazy routes that loaded after the span was created but before it ended.