Title: wrapFetchWithSentry's injected trace meta tags break React 19 document hydration (error #418 on every SSR page) · Issue #21915 · getsentry/sentry-javascript · GitHub
Open Graph Title: wrapFetchWithSentry's injected trace meta tags break React 19 document hydration (error #418 on every SSR page) · Issue #21915 · getsentry/sentry-javascript
X Title: wrapFetchWithSentry's injected trace meta tags break React 19 document hydration (error #418 on every SSR page) · Issue #21915 · 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/21915
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"wrapFetchWithSentry's injected trace meta tags break React 19 document hydration (error #418 on every SSR page)","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues [https://github.com/getsentry/sentry-javascript/issues](\u003chttps://github.com/getsentry/sentry-javascript/issues>)\n- [X] I have reviewed the documentation [https://docs.sentry.io/](\u003chttps://docs.sentry.io/>)\n- [X] I am using the latest SDK release [https://github.com/getsentry/sentry-javascript/releases](\u003chttps://github.com/getsentry/sentry-javascript/releases>)\n\n### How do you use Sentry?\n\nSentry Saas ([sentry.io](\u003chttp://sentry.io>))\n\n### Which SDK are you using?\n\n@sentry/tanstackstart-react\n\n### SDK Version\n\n10.63.0\n\n### Framework Version\n\nReact 19.2.4, @tanstack/react-start 1.168.26 (Vite 8 + Nitro)\n\n### Link to Sentry event\n\n*No response*\n\n### Reproduction Example/SDK Setup\n\nStandard TanStack Start setup per the SDK docs — the relevant part is the server entry:\n\n```ts\n// src/server.ts\nimport '../instrument.server.mjs'\nimport { wrapFetchWithSentry } from '@sentry/tanstackstart-react'\nimport handler, { createServerEntry } from '@tanstack/react-start/server-entry'\n\nexport default createServerEntry(\n wrapFetchWithSentry({\n fetch(request: Request) {\n return handler.fetch(request)\n },\n }),\n)\n```\n\n```js\n// instrument.server.mjs\nimport * as Sentry from '@sentry/tanstackstart-react'\nSentry.init({\n dsn: process.env.VITE_SENTRY_DSN,\n tracesSampleRate: 0,\n})\n```\n\nClient entry is the TanStack Start default (whole-document hydration):\n\n```tsx\n// src/client.tsx\nhydrateRoot(\n document,\n \u003cStrictMode>\n \u003cStartClient />\n \u003c/StrictMode>,\n)\n```\n\n### Steps to Reproduce\n\n1. Create a TanStack Start (React 19) app and set up `@sentry/tanstackstart-react` >= 10.55.0 per the docs, including `wrapFetchWithSentry` in the server entry.\n2. Make a production build and run it with a server-side DSN configured (any syntactically valid DSN reproduces it — the SDK just needs to be enabled).\n3. Open any SSR page with the browser console open.\n\nWhat happens: `wrapFetchWithSentry` → `injectMetaTagsInResponse` inserts `getTraceMetaTags()` right after `\u003chead>`. `getTraceMetaTags()` joins the two meta tags with `'\\n'` ([packages/core/src/utils/meta.ts](\u003chttps://github.com/getsentry/sentry-javascript/blob/master/packages/core/src/utils/meta.ts>)), so the served HTML is:\n\n```html\n\u003chead>\u003cmeta name=\"sentry-trace\" content=\"...\"/>\n\u003cmeta name=\"baggage\" content=\"...\"/>\u003cmeta charSet=\"utf-8\"/>...\n```\n\nThat newline becomes a whitespace **text node** inside `\u003chead>`. React 19's whole-document hydration tolerates unexpected *elements* in `\u003chead>`/`\u003cbody>`, but not unexpected *text nodes* — hydration fails with error [#418](\u003chttps://github.com/getsentry/sentry-javascript/issues/418>) and the entire document is re-rendered on the client.\n\nI isolated this on a production deployment by editing the served HTML and re-loading it in place (`document.open()/write()/close()`), same environment for all variants:\n\n\u003c!-- linear:table-colwidths:400,400 -->\n| served HTML variant | result |\n| -- | -- |\n| original (both metas + `\\n` between them) | [#418](\u003chttps://github.com/getsentry/sentry-javascript/issues/418>) on every load |\n| both meta tags removed | no error |\n| metas kept, only the `\\n` between them removed | **no error** |\n| metas removed entirely, a bare `\\n` inserted after `\u003chead>` | [#418](\u003chttps://github.com/getsentry/sentry-javascript/issues/418>) |\n\nSo the text node is both necessary and sufficient; the meta elements themselves are fine. Not reproducible in dev (SDK disabled → no injection), which is presumably why this hasn't been reported — it only shows in deployed apps.\n\nIntroduced with the meta tag injection in [#21144](\u003chttps://github.com/getsentry/sentry-javascript/issues/21144>) (10.55.0). Still present in 10.63.0. Possibly the same phenomenon as the \"benign React [#418](\u003chttps://github.com/getsentry/sentry-javascript/issues/418>)\" mentioned in passing in getsentry/sentry-javascript#21770.\n\nSuggested fix: join the tags without the newline in `getTraceMetaTags()` (or inject without whitespace in `addMetaTagToHead`).\n\n### Expected Result\n\nThe injected trace meta tags don't interfere with React hydration: no hydration errors, and the server-rendered DOM is preserved.\n\n### Actual Result\n\nEvery SSR page load logs:\n\n```\nUncaught Error: Minified React error #418; visit https://react.dev/errors/418?args[]=HTML&args[]= ...\n```\n\n(\"Hydration failed because the server rendered HTML didn't match the client.\")\n\nReact recovers by re-rendering the whole document on the client, so the page *looks* fine, but:\n\n* SSR benefits are lost on every page load (full client re-render), with possible flicker and lost pre-hydration input/focus.\n* The recovery re-render rebuilds `\u003chead>` and **wipes the injected** `sentry-trace`**/**`baggage` **meta tags**, so the distributed-tracing linkage this feature exists to provide is lost as well.\n* The constant [#418](\u003chttps://github.com/getsentry/sentry-javascript/issues/418>) noise masks real hydration bugs.\n\n### Additional Context\n\n*No response*\n\n### Priority\n\nReact with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.","author":{"url":"https://github.com/zenato","@type":"Person","name":"zenato"},"datePublished":"2026-07-02T09:27:28Z","url":"https://github.com/getsentry/sentry-javascript/issues/21915"}
| 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:d07c4eca-93f3-cefd-7806-3938e5fa10e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D14:25C00B:2E1ED6:3D2C62:6B04B74E |
| html-safe-nonce | eee5ff277e279cb3e3a8b3979c91700a761d17d2fff8def13d323eac797ad05a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDE0OjI1QzAwQjoyRTFFRDY6M0QyQzYyOjZCMDRCNzRFIiwidmlzaXRvcl9pZCI6IjU2NzQ2MDU2NzMzOTMyMDcxMTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 174cd901f3da7a25754ab86eeb99d4d2aa83618829941a944ee284ba7a0d2d94 |
| hovercard-subject-tag | issue:4793088659 |
| 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/21915/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da603074738bc85680e8457177c5f8b23d314b64f2fedfe917cd0c05b0e03fce/getsentry/sentry-javascript/issues/21915 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da603074738bc85680e8457177c5f8b23d314b64f2fedfe917cd0c05b0e03fce/getsentry/sentry-javascript/issues/21915 |
| 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 | zenato |
| hostname | github.com |
| expected-hostname | github.com |
| None | 378bd702ac792b3550e484ad39d9a898fcd25bb52ba6962b0c9cc457c1ea71c7 |
| 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 | b032e77f1ea437ede6c115446a0a467709b468e7 |
| 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