Title: RR6 wrapUseRoutes creates a new component on every render · Issue #8962 · getsentry/sentry-javascript · GitHub
Open Graph Title: RR6 wrapUseRoutes creates a new component on every render · Issue #8962 · getsentry/sentry-javascript
X Title: RR6 wrapUseRoutes creates a new component on every render · Issue #8962 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/8962
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"RR6 wrapUseRoutes creates a new component on every render","articleBody":"### Is there an existing issue for this?\r\n\r\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\r\n- [X] I have reviewed the documentation https://docs.sentry.io/\r\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\r\n\r\n### How do you use Sentry?\r\n\r\nSentry Saas (sentry.io)\r\n\r\n### Which SDK are you using?\r\n\r\n@sentry/react\r\n\r\n### SDK Version\r\n\r\n7.68.0\r\n\r\n### Framework Version\r\n\r\nReact 18.2.0\r\n\r\n### Link to Sentry event\r\n\r\n_No response_\r\n\r\n### SDK Setup\r\n\r\n_No response_\r\n\r\n### Steps to Reproduce\r\n\r\nWhen 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\r\n\r\n1. Set up a React project using React Router v6 and Sentry, using `wrapUseRoutes`\r\n2. 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.\r\n3. Add a `useEffect` with no dependencies in a route component to log when it mounts / un-mounts.\r\n4. Cause the outer component to re-render and notice that the route component un-mounts and re-mounts.\r\n5. Remove the use of `wrapUseRoutes` and repeat, noting that the route component remains mounted.\r\n\r\n### Expected Result\r\n\r\nRoutes behave the same whether using React Router's `useRoutes` or one wrapped using `wrapUseRoutes`. \r\n\r\n### Actual Result\r\n\r\nRoute components un-mount and re-mount each time the component containing the call to `useRoutes` re-renders.","author":{"url":"https://github.com/jameshoward","@type":"Person","name":"jameshoward"},"datePublished":"2023-09-06T14:54:46Z","url":"https://github.com/getsentry/sentry-javascript/issues/8962"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3e89bc29-3da3-3c80-5620-3e3d1818de85 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D28:F551D:5E407F:7E9D59:6B04A104 |
| html-safe-nonce | c8d51ba47583ddc833983c18c64abbda10a24720f6b9d95b6b613294591465ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDI4OkY1NTFEOjVFNDA3Rjo3RTlENTk6NkIwNEExMDQiLCJ2aXNpdG9yX2lkIjoiMjMwNzc1OTAzNDU3NDYxMDY5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 05b2254c181721c80ab34fe7761243e1cbb496cb6c164dde82678a4b6f882450 |
| hovercard-subject-tag | issue:1884197145 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/8962/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb6bde056095e03040ffa3d7b46d783fa75b7a39518e6a9fd283fd685da8a2ec/getsentry/sentry-javascript/issues/8962 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb6bde056095e03040ffa3d7b46d783fa75b7a39518e6a9fd283fd685da8a2ec/getsentry/sentry-javascript/issues/8962 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jameshoward |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9784b6f42e2d5eac4e394fa88cad134c0dc5b6662b4ff2787a1ed1ef5a96331d |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3fd14143b75b2af7b76bbd23b069867d091adfcc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width