fix(devtools-vite): inject the bus port into pre-bundled dependency chunks #538
When Vite pre-bundles @tanstack/react-devtools from npm, the browser event bus client always connects to port 4206. The server bus can use another port (eventBusConfig.port, or a random port after EADDRINUSE), so the client cannot connect. This PR also injects the port, host, and protocol into Vite's pre-bundled chunks under node_modules/.vite/deps*.
🎯 Changes#
connection-injectionskipped pre-bundled chunks: their ids (for example/node_modules/.vite/deps/BRS44MK7-KeTQTbh5.js) do not contain@tanstack/devtools. As a result,__TANSTACK_DEVTOOLS_PORT__stayed in the code andgetDefaultPortreturned 4206.- The filter now also accepts ids that contain
/.vite/deps. The placeholder check still limits the transform to modules that contain the placeholders. Other packages stay untouched. - The examples did not show the bug: they link packages with
workspace:*, and Vite does not pre-bundle linked packages.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run
vitest runinpackages/devtools-vite: 22 tests pass, with a new test for a.vite/depsid.eslintandtscinpackages/devtools-vite: pass.- I did not run the full
pnpm test:pr.
Manual test
- Use the reproduction in #536: install
@tanstack/react-devtoolsfrom npm, and setdevtools({ eventBusConfig: { port: 4260 } }). - Before this fix: the browser logs
WebSocket connection error, and the served.vite/depschunk still contains__TANSTACK_DEVTOOLS_PORT__. - After this fix: the server bus logs
New WebSocket client connected, and the chunk contains4260.
How this PR makes testing easy
A unit test in packages/devtools-vite/tests/index.test.ts transforms a .vite/deps id and expects the port.
Linked issues#
Fixes #536
Risk / rollback#
Low. Only modules that contain the devtools placeholders change. To undo, revert this PR.
🤖 Generated with Claude Code
Summary by CodeRabbit#
- Bug Fixes
- Vite-prebundled dependencies now receive the configured connection details, helping clients connect when the server uses a port other than the default.
- 1
View your CI Pipeline Execution ↗ for commit a2b07183f4cc639beac8dd571e1551f7ad3350c7
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 4s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-02 13:02:36UTCView your CI Pipeline Execution ↗ for commit a2b07183f4cc639beac8dd571e1551f7ad3350c7
Command Status Duration Result nx run-many --target=test:e2e --parallel=1 --pr...✅ Succeeded 1m 15s View ↗ nx affected --targets=test:eslint,test:sherif,t...✅ Succeeded 40s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 4s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-02 13:04:21UTCMore templates
- @tanstack/devtools-example-angular-a11y-devtools
- @tanstack/devtools-example-angular-basic
- @tanstack/devtools-example-angular-panel
- ssr
- @tanstack/devtools-example-angular-with-devtools
- @tanstack/devtools-example-preact-basic
- @tanstack/devtools-custom-devtools-preact
- @tanstack/react-devtools-a11y-example
- @tanstack/devtools-example-react-basic
- start-repro
- @tanstack/devtools-custom-devtools
- tanstack-start-example-counter
- @tanstack/devtools-example-react-https
- start
- start-cloudflare
- start-nitro
- @tanstack/devtools-example-react-time-travel
- @tanstack/solid-devtools-a11y-example
- @tanstack/devtools-example-solid-basic
- @tanstack/devtools-example-devtools-ui
- @tanstack/devtools-example-solid-start
- @tanstack/query-example-vue-basic
@tanstack/angular-devtools
npm i https://pkg.pr.new/@tanstack/angular-devtools@538@tanstack/devtools
npm i https://pkg.pr.new/@tanstack/devtools@538@tanstack/devtools-a11y
npm i https://pkg.pr.new/@tanstack/devtools-a11y@538@tanstack/devtools-bundler-core
npm i https://pkg.pr.new/@tanstack/devtools-bundler-core@538@tanstack/devtools-client
npm i https://pkg.pr.new/@tanstack/devtools-client@538@tanstack/devtools-rspack
npm i https://pkg.pr.new/@tanstack/devtools-rspack@538@tanstack/devtools-ui
npm i https://pkg.pr.new/@tanstack/devtools-ui@538@tanstack/devtools-utils
npm i https://pkg.pr.new/@tanstack/devtools-utils@538@tanstack/devtools-vite
npm i https://pkg.pr.new/@tanstack/devtools-vite@538@tanstack/devtools-webmcp
npm i https://pkg.pr.new/@tanstack/devtools-webmcp@538@tanstack/devtools-event-bus
npm i https://pkg.pr.new/@tanstack/devtools-event-bus@538@tanstack/devtools-event-client
npm i https://pkg.pr.new/@tanstack/devtools-event-client@538@tanstack/preact-devtools
npm i https://pkg.pr.new/@tanstack/preact-devtools@538@tanstack/react-devtools
npm i https://pkg.pr.new/@tanstack/react-devtools@538@tanstack/solid-devtools
npm i https://pkg.pr.new/@tanstack/solid-devtools@538@tanstack/svelte-devtools
npm i https://pkg.pr.new/@tanstack/svelte-devtools@538@tanstack/vue-devtools
npm i https://pkg.pr.new/@tanstack/vue-devtools@538commit:
a2b0718AlemTuzlak merged this7cb0a8d
AlemTuzlak closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: TanStack/devtools/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
cc9c8fc7-1f54-432a-aeae-ec7eed80f6e7📥 Commits
Reviewing files that changed from the base of the PR and between afa01fec1751308eb5f60e737e408f2fc34e669a and a2b07183f4cc639beac8dd571e1551f7ad3350c7.
📒 Files selected for processing (3)
.changeset/vite-deps-bus-port.mdpackages/devtools-vite/src/plugin.tspackages/devtools-vite/tests/index.test.tsIncluded review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
📝 Walkthrough
Walkthrough#
The connection-injection transform now processes Vite pre-bundled dependency chunks when they contain a connection placeholder. A test checks port replacement, and a patch changeset records the update.
Changes#
Vite Connection Injection
packages/devtools-vite/src/plugin.ts,packages/devtools-vite/tests/index.test.ts,.changeset/vite-deps-bus-port.md/.vite/depsthrough its package-ID filter. The test checks that the port placeholder is replaced with4206. The changeset records a patch release for@tanstack/devtools-vite.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
a2b07Matching Vite pre-bundled chunks receive the event-bus connection settings, with the client’s existing defaults preserved. No actionable merge-blocking risk remains.
Architecture Summary#
Architecture risk: 🔵 Low · up to
a2b07The change affects 1 system.
Changed systems:
packages/devtools-viteArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
Before / after behavior
/.vite/depsthrough its package-ID filter. Previously, IDs without either@tanstack/devtoolsor@tanstack/event-buswere skipped; those IDs are now processed when they contain a placeholder.const port = 4206.@tanstack/devtools-viteand a release note describing the event-bus settings injected into Vite pre-bundled dependency chunks and the connection failure when an npm-installed client uses the default port4206while the server uses another port.🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#536] requires the browser event-bus client to use the server bus port, including a fallback port. The PR extendsconnection-injectionto Vite pre-bundled IDs under/.vite/depswhile retain…connection-injectionfilter update, and the focused test all support issue [#536]. No unrelated product behavior or unrelated files appear in the supplied whole-PR summary.✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share