fix(devtools-vite): inject the bus port into pre-bundled dependency chunks by AlemTuzlak · Pull Request #538 · TanStack/devtools · GitHub
Skip to content

fix(devtools-vite): inject the bus port into pre-bundled dependency chunks - #538

Open
AlemTuzlak wants to merge 1 commit into
mainfrom
fix/536-prebundled-bus-port
Open

AlemTuzlak wants to merge 1 commit into
mainfrom
fix/536-prebundled-bus-port

Conversation

@AlemTuzlak

@AlemTuzlak AlemTuzlak commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

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-injection skipped 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 and getDefaultPort returned 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 run in packages/devtools-vite: 22 tests pass, with a new test for a .vite/deps id.
  • eslint and tsc in packages/devtools-vite: pass.
  • I did not run the full pnpm test:pr.

Manual test

  1. Use the reproduction in Pre-bundled client ignores the event bus port from devtools-vite #536: install @tanstack/react-devtools from npm, and set devtools({ eventBusConfig: { port: 4260 } }).
  2. Before this fix: the browser logs WebSocket connection error, and the served .vite/deps chunk still contains __TANSTACK_DEVTOOLS_PORT__.
  3. After this fix: the server bus logs New WebSocket client connected, and the chunk contains 4260.

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.

…hunks

Vite pre-bundles npm installs of @tanstack/react-devtools into chunks under
node_modules/.vite/deps. Their ids do not contain "@tanstack/devtools", so
connection-injection skipped them and __TANSTACK_DEVTOOLS_PORT__ stayed in
the code. The browser then always dialed 4206, also when the server bus moved
to another port.

The examples link packages with workspace:*, and Vite does not pre-bundle
linked packages, so the examples did not show the bug.

Fixes #536
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

@nx-cloud

nx-cloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a2b0718

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:36 UTC

@nx-cloud

nx-cloud Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a2b0718

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:21 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 2, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-bundled client ignores the event bus port from devtools-vite

1 participant