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
When using wrapUseRoutes we noticed that route components were being unmounted and remounted if the component where useRoutes is called was re-rendered. After some digging we realised it is because each time the wrapped useRoutes function is called, a new SentryRoutes component will be created (i.e. a totally new function component, not a re-rendering of the component) - https://github.com/getsentry/sentry-javascript/blob/develop/packages/react/src/reactrouterv6.tsx#L231
Set up a React project using React Router v6 and Sentry, using wrapUseRoutes
In the component that renders the element returned from useRoutes, add a useState and a button to trigger setting the state, which will force the component to re-render.
Add a useEffect with no dependencies in a route component to log when it mounts / un-mounts.
Cause the outer component to re-render and notice that the route component un-mounts and re-mounts.
Remove the use of wrapUseRoutes and repeat, noting that the route component remains mounted.
Expected Result
Routes behave the same whether using React Router's useRoutes or one wrapped using wrapUseRoutes.
Actual Result
Route components un-mount and re-mount each time the component containing the call to useRoutes re-renders.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/react
SDK Version
7.68.0
Framework Version
React 18.2.0
Link to Sentry event
No response
SDK Setup
No response
Steps to Reproduce
When using
wrapUseRoutes
we noticed that route components were being unmounted and remounted if the component whereuseRoutes
is called was re-rendered. After some digging we realised it is because each time the wrappeduseRoutes
function is called, a newSentryRoutes
component will be created (i.e. a totally new function component, not a re-rendering of the component) - https://github.com/getsentry/sentry-javascript/blob/develop/packages/react/src/reactrouterv6.tsx#L231wrapUseRoutes
useRoutes
, add auseState
and a button to trigger setting the state, which will force the component to re-render.useEffect
with no dependencies in a route component to log when it mounts / un-mounts.wrapUseRoutes
and repeat, noting that the route component remains mounted.Expected Result
Routes behave the same whether using React Router's
useRoutes
or one wrapped usingwrapUseRoutes
.Actual Result
Route components un-mount and re-mount each time the component containing the call to
useRoutes
re-renders.The text was updated successfully, but these errors were encountered: