Title: data-tsd-source inject-source plugin causes hydration mismatch in SSR (TanStack Start) · Issue #405 · TanStack/devtools · GitHub
Open Graph Title: data-tsd-source inject-source plugin causes hydration mismatch in SSR (TanStack Start) · Issue #405 · TanStack/devtools
X Title: data-tsd-source inject-source plugin causes hydration mismatch in SSR (TanStack Start) · Issue #405 · TanStack/devtools
Description: Description The inject-source plugin in @tanstack/devtools-vite causes React hydration mismatch warnings in TanStack Start (SSR) projects. The data-tsd-source attributes are injected with different line numbers on the server vs client tr...
Open Graph Description: Description The inject-source plugin in @tanstack/devtools-vite causes React hydration mismatch warnings in TanStack Start (SSR) projects. The data-tsd-source attributes are injected with different...
X Description: Description The inject-source plugin in @tanstack/devtools-vite causes React hydration mismatch warnings in TanStack Start (SSR) projects. The data-tsd-source attributes are injected with different...
Opengraph URL: https://github.com/TanStack/devtools/issues/405
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"data-tsd-source inject-source plugin causes hydration mismatch in SSR (TanStack Start)","articleBody":"## Description\n\nThe `inject-source` plugin in `@tanstack/devtools-vite` causes React hydration mismatch warnings in TanStack Start (SSR) projects. The `data-tsd-source` attributes are injected with different line numbers on the server vs client transform passes, because other Vite plugins (e.g. `tanstackStart()`, `viteReact()`) shift line numbers differently between SSR and client bundles.\n\n## Reproduction\n\n1. Create a TanStack Start project with `@tanstack/devtools-vite` v0.6.0\n2. Add `devtools()` to `vite.config.ts`\n3. Navigate to any SSR-rendered route\n4. Observe console warning:\n\n```\nA tree hydrated but some attributes of the server rendered HTML didn't match the client properties.\n\n\u003cdiv\n+ data-tsd-source=\"/src/routes/simulations/$slug/editor.tsx:632:5\"\n- data-tsd-source=\"/src/routes/simulations/$slug/editor.tsx:636:5\"\n>\n```\n\nLine numbers are consistently off by a fixed offset (4 lines in my case) — the server and client transforms produce different source locations for the same JSX elements.\n\n## Root Cause\n\nIn `plugin.ts`, the `inject-source` Vite plugin's `apply` function only checks `config.mode === 'development'`:\n\n```typescript\napply(config) {\n return config.mode === 'development' && injectSourceConfig.enabled\n},\n```\n\nThe `transform` hook does not check the `ssr` boolean that Vite passes as the third argument. Since `data-tsd-source` is only useful on the client (for click-to-source in the devtools UI), injecting it during the SSR pass creates the mismatch.\n\n## Suggested Fix\n\nSkip source injection during the SSR transform pass. The Vite `transform` hook receives `{ ssr: boolean }` as the third argument:\n\n```typescript\ntransform(code, id, options) {\n if (options?.ssr) return; // Only inject on client\n // ... existing Babel transform\n}\n```\n\nThis would eliminate the hydration mismatch while preserving click-to-source functionality on the client.\n\n## Workaround\n\nDisable source injection entirely:\n\n```typescript\ndevtools({ injectSource: { enabled: false } })\n```\n\nThis removes the hydration warning but loses click-to-source in the devtools UI.\n\n## Environment\n\n- `@tanstack/devtools-vite`: 0.6.0\n- `@tanstack/react-start`: latest\n- React 19\n- Vite 7","author":{"url":"https://github.com/twentynineteen","@type":"Person","name":"twentynineteen"},"datePublished":"2026-03-26T09:58:22Z","url":"https://github.com/TanStack/devtools/issues/405"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:5dd89502-6e69-f495-ccef-0d868daf3ad9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5FE:3166AC:27F028A:347E9AC:6AF9AA84 |
| html-safe-nonce | 2d4326ac0b3a634eb43e98133dcabe582284eeb0e4bb7966288071b8ab1910f8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUZFOjMxNjZBQzoyN0YwMjhBOjM0N0U5QUM6NkFGOUFBODQiLCJ2aXNpdG9yX2lkIjoiNjA5Mjk4NTYxMDI5MTIyNzI2OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 46cb09cc7303b14aa9a1e550256f05ffb267ec9960de94b8b5209f26e99ed35a |
| hovercard-subject-tag | issue:4142369440 |
| 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/TanStack/devtools/405/issue_layout |
| twitter:image | https://opengraph.githubassets.com/50a43d5767686ad0d108ce8c095559f701d79f6c7105e00d9abdb37e00667aaa/TanStack/devtools/issues/405 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/50a43d5767686ad0d108ce8c095559f701d79f6c7105e00d9abdb37e00667aaa/TanStack/devtools/issues/405 |
| og:image:alt | Description The inject-source plugin in @tanstack/devtools-vite causes React hydration mismatch warnings in TanStack Start (SSR) projects. The data-tsd-source attributes are injected with different... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | twentynineteen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-preview |
| go-import | github.com/TanStack/devtools git https://github.com/TanStack/devtools.git |
| octolytics-dimension-user_id | 72518640 |
| octolytics-dimension-user_login | TanStack |
| octolytics-dimension-repository_id | 1026402761 |
| octolytics-dimension-repository_nwo | TanStack/devtools |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1026402761 |
| octolytics-dimension-repository_network_root_nwo | TanStack/devtools |
| 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 | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width