You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Configure React Router with Sentry wrapper. But Lazy import routes, e.g. something like:
// user routes bundle loaded lazilyconstUserRoutes=lazy(()=>import("./UserRoutes"));constRouter: FC=()=>{const{ user }=useContext(UserContext);constsentryCreateBrowserRouter: typeofcreateBrowserRouter=Sentry.wrapCreateBrowserRouterV7(createBrowserRouter);constrouter=sentryCreateBrowserRouter(createRoutesFromElements(<><Routepath="login"element={<Login/>}/><Routepath="*"element={user ? (// All other routes for logged in users<Suspensefallback={<LoadingPage/>}><UserRoutes/></Suspense>) : (// All other routes when not logged in, just navigate back to login page<Navigateto="/login"/>)}/></>,),);
Steps to Reproduce
Configured React Router with Sentry Wrappers
Lazy load routes
Navigate to "/" (This initializes Sentry's route change subscriptions using routes available on initial page load)
Navigate to lazy loaded routes, e.g. "/profile"
Expected Result
Navigation transaction span started using path "/profile"
Actual Result
Navigation transaction span started using path "/*"
This appears to be because the routes are only extracted once on mount:
// `props.children` is purposely not included in the dependency array, because we do not want to re-run this effect
// when the children change. We only want to start transactions when the location or navigation type change.
[location,navigationType],
);
And even though additional routes are lazy loaded, and the route name is correctly passed from the navigation event, when the name is normalized, it can't find the route, so falls back to the parent catch-all "/*"
Hello, thanks for writing in and already trying to investigate this! We'll take a look at this.
However, if you are interested in contributing, feel free to let me know and open a PR! :)
Just for clarification: the first link to the code you posted is probably not the reason, as this is not the function which is used when setting up the routes with JSX. This would be this function:
#15039 will add support for lazy-loaded components/pages on navigations.
However, adding support for lazy-loaded routes is a bit more tricky, as we are currently unable to access the lazy-loaded sub-Routes, without breaking lazy-loading.
I opened an issue to discuss how we can implement that - #15040
Is there an existing issue for this?
How do you use Sentry?
Self-hosted/on-premise
Which SDK are you using?
@sentry/react
SDK Version
8.47.0
Framework Version
React 18.3.1
Link to Sentry event
No response
Reproduction Example/SDK Setup
Init sentry with React Router browser tracing integration.
Configure React Router with Sentry wrapper. But Lazy import routes, e.g. something like:
Steps to Reproduce
"/"
(This initializes Sentry's route change subscriptions using routes available on initial page load)"/profile"
Expected Result
Navigation transaction span started using path
"/profile"
Actual Result
Navigation transaction span started using path
"/*"
This appears to be because the routes are only extracted once on mount:
sentry-javascript/packages/react/src/reactrouterv6-compat-utils.tsx
Lines 602 to 631 in 9f74bc9
And even though additional routes are lazy loaded, and the route name is correctly passed from the navigation event, when the name is normalized, it can't find the route, so falls back to the parent catch-all
"/*"
sentry-javascript/packages/react/src/reactrouterv6-compat-utils.tsx
Lines 333 to 342 in 9f74bc9
The text was updated successfully, but these errors were encountered: