fix(devtools-bundler-core): open source files outside cwd and end bad open-source requests by AlemTuzlak · Pull Request #541 · TanStack/devtools · GitHub
Skip to content

fix(devtools-bundler-core): open source files outside cwd and end bad open-source requests - #541

Open
AlemTuzlak wants to merge 1 commit into
mainfrom
fix/open-source-path-outside-cwd
Open

AlemTuzlak wants to merge 1 commit into
mainfrom
fix/open-source-path-outside-cwd

Conversation

@AlemTuzlak

@AlemTuzlak AlemTuzlak commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

"Go to Source" opens a wrong path when the source file is outside the current working directory, for example in a monorepo package or when Vite runs from another directory. This PR makes the open-source handler keep the absolute path of such files. It also answers 400 for a bad source, so the request no longer stays pending.

🎯 Changes

  • addSourceToJsx strips process.cwd() from the module path. A file outside cwd keeps its absolute path, and the handler then added cwd again: /repo/apps/web/repo/packages/pkg/src/panel.tsx.
  • The handler now uses the absolute path when the cwd-relative file does not exist and the absolute file does. Files inside cwd resolve as before.
  • A missing or malformed source returned without res.end(), so the request stayed pending until the browser timed out (the server part of Click-to-source sends empty source= and hangs because setDisabledAfterClick(true) runs before reading highlightState.dataSource #451). It now answers 400.
  • The Vite and Rspack plugins both use this shared handler.

✅ 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-bundler-core: 200 tests pass. The 3 new and updated tests failed before the fix.
  • eslint, tsc, and prettier --check on the changed files: pass.
  • I did not run the full pnpm test:pr.

Manual test

  1. In a monorepo, run Vite from apps/web and render a component from packages/pkg. Or use the StackBlitz repro in Click-to-code does not work when command run from different directory #281.
  2. Before this fix: click-to-source on that component sends a path with cwd added twice, and the editor opens an empty file.
  3. After this fix: the editor opens packages/pkg/src/... at the right line.
  4. Open /__tsd/open-source?source= in the browser. Before: pending forever. After: 400.

How this PR makes testing easy

Unit tests in utils.test.ts cover a file outside cwd (the repo root package.json) and the 400 answers.

Linked issues

Fixes #281
Fixes #176
Refs #451 (the client part of #451 was fixed in @tanstack/devtools@0.12.3)

Risk / rollback

Low. If both the cwd-relative path and the absolute path exist, the cwd-relative path wins, as before. To undo, revert this PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • “Go to Source” now handles files outside the current working directory correctly.
    • Requests with missing or invalid source paths now receive an HTTP 400 response instead of remaining pending.

… open-source requests

addSourceToJsx strips cwd from the module path. A file outside cwd (a
monorepo package, or Vite run from another directory) keeps its absolute
path, and the open-source handler then prefixed cwd again. The editor got
paths like /repo/apps/web/repo/packages/pkg/src/panel.tsx.

The handler now uses the absolute path when the cwd-relative file does not
exist and the absolute one does.

A missing or malformed `source` returned without ending the response, so the
request stayed pending until the browser timed out. It now answers 400.

Fixes #281
Fixes #176
Refs #451
@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 32e150a

Command Status Duration Result
nx run-many --target=test:e2e --parallel=1 --pr... ✅ Succeeded 1m 13s View ↗
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 58s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-02 13:17:45 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.

Click-to-code does not work when command run from different directory Go to source feature not working on Linux

1 participant