Title: React Hooks issue with react-router-v6 integration · Issue #5309 · getsentry/sentry-javascript · GitHub
Open Graph Title: React Hooks issue with react-router-v6 integration · Issue #5309 · getsentry/sentry-javascript
X Title: React Hooks issue with react-router-v6 integration · Issue #5309 · 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/5309
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"React Hooks issue with react-router-v6 integration","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 package are you using?\r\n\r\n@sentry/react\r\n\r\n### SDK Version\r\n\r\n7.2.0\r\n\r\n### Framework Version\r\n\r\n7.2.0\r\n\r\n### Steps to Reproduce\r\n\r\n**1.** Starting a react application with Vite.js in dev mode with react-refresh\r\n**2.** Adding a simple Application like this one\r\n\r\n```js\r\nimport React from 'react';\r\nimport { createRoot } from 'react-dom/client';\r\nimport { BrowserRouter, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes, Routes, Route } from 'react-router-dom';\r\nimport * as Sentry from '@sentry/react';\r\nimport { BrowserTracing } from '@sentry/tracing';\r\nimport { APP_ENVIRONMENT, SENTRY_DSN } from './config';\r\n\r\nSentry.init({\r\n dsn: SENTRY_DSN,\r\n integrations: [\r\n new BrowserTracing({\r\n routingInstrumentation: Sentry.reactRouterV6Instrumentation(React.useEffect, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes),\r\n }),\r\n ],\r\n environment: APP_ENVIRONMENT,\r\n tracesSampleRate: 1.0,\r\n});\r\n\r\nconst SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes);\r\n\r\n\r\nfunction render() {\r\n const container = document.getElementById('root');\r\n if (!container) {\r\n return null;\r\n }\r\n const root = createRoot(container);\r\n root.render(\r\n \u003cReact.StrictMode>\r\n \u003cBrowserRouter>\r\n \u003cSentryRoutes>\r\n \u003cRoute path=\"/\" element={\u003cReact.Fragment />} />\r\n \u003c/SentryRoutes>\r\n \u003c/BrowserRouter>\r\n \u003c/React.StrictMode>,\r\n );\r\n}\r\n\r\n(() => {\r\n render();\r\n})();\r\n```\r\n\r\nSame code is in the official doc of Sentry https://docs.sentry.io/platforms/javascript/guides/react/configuration/integrations/react-router/\r\n**3.** The app starts normally in dev mode.\r\n**4.** As soon as I perform one modification, the front-end application crash completely. I need to close the tab and stop the application.\r\n\r\nWhen I remove \r\n```\r\nnew BrowserTracing({\r\n routingInstrumentation: Sentry.reactRouterV6Instrumentation(React.useEffect, useLocation, useNavigationType, createRoutesFromChildren, matchRoutes)\r\n})\r\n```\r\n\r\nfrom the sentry integrations, everything goes back to normal\r\n\r\n### Expected Result\r\n\r\nWhen I do a change in local while I am developing, I should see my changes in live without my app crashing. I should be able to use BrowserTracing with Sentry without my app having issues\r\n\r\n### Actual Result\r\n\r\n```\r\nWarning: React has detected a change in the order of Hooks called by SentryRoutes. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks\r\n```\r\n\r\nThere is issue in the order of hooks execution while adding the BrowserTracing from Sentry.\r\n\u003cimg width=\"762\" alt=\"Screenshot 2022-06-24 at 18 19 44\" src=\"https://user-images.githubusercontent.com/22744840/175516722-7474a326-4f50-42d3-a082-631f9699da90.png\">\r\n\r\nVite.js config to start the app.\r\n```js\r\nimport { defineConfig, loadEnv } from 'vite';\r\nimport { visualizer } from 'rollup-plugin-visualizer';\r\nimport react from '@vitejs/plugin-react';\r\nimport svgrPlugin from 'vite-plugin-svgr';\r\n\r\nexport default defineConfig(({ mode }) => {\r\n const env = loadEnv(mode, process.cwd());\r\n\r\n // expose .env as process.env instead of import.meta since jest does not import meta yet\r\n const envWithProcessPrefix = Object.entries(env).reduce((prev, [key, val]) => {\r\n return {\r\n ...prev,\r\n ['process.env.' + key]: `\"${val}\"`,\r\n };\r\n }, {});\r\n\r\n return {\r\n server: {\r\n port: 3000,\r\n },\r\n preview: {\r\n port: 8080,\r\n },\r\n define: envWithProcessPrefix,\r\n build: {\r\n sourcemap: true,\r\n outDir: 'build',\r\n minify: 'esbuild',\r\n },\r\n plugins: [\r\n react(),\r\n svgrPlugin({\r\n svgrOptions: {\r\n // ...svgr options (https://react-svgr.com/docs/options/)\r\n },\r\n }),\r\n visualizer(),\r\n ],\r\n };\r\n});\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/alexabidri","@type":"Person","name":"alexabidri"},"datePublished":"2022-06-24T10:26:14Z","url":"https://github.com/getsentry/sentry-javascript/issues/5309"}
| 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:6c52da66-4450-2249-b4b6-9fa660ec059b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D85E:376486:80C6D0:B51161:6B0481B8 |
| html-safe-nonce | 7d42c290667b65021631278baa78a691d39d02d8662092b94b9c00eea6030ffa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODVFOjM3NjQ4Njo4MEM2RDA6QjUxMTYxOjZCMDQ4MUI4IiwidmlzaXRvcl9pZCI6IjY5ODM2OTkzNjE0Nzc5ODQ2OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c2b333796483ad9989f9743e7b6339c8761d9cbcb6c779d5f46e7b7828d5df3e |
| hovercard-subject-tag | issue:1283573258 |
| 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/5309/issue_layout |
| twitter:image | https://opengraph.githubassets.com/408349540d4d123b6a66b3da359acc9dc9111e77e5c7bb24b6c49e3c24cc503c/getsentry/sentry-javascript/issues/5309 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/408349540d4d123b6a66b3da359acc9dc9111e77e5c7bb24b6c49e3c24cc503c/getsentry/sentry-javascript/issues/5309 |
| 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 | alexabidri |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0366ddfb372682a32e92a5d86155cb08fa83e5bbe79953a968789f2f7e24c511 |
| 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 | ed3f2e01f6b7672780c586c8af0e72726374d7b6 |
| 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