Click-to-source sends empty source= and hangs because setDisabledAfterClick(true) runs before reading highlightState.dataSource
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 冷清
- 技術堆疊
- react, typescript, vite
研究方向
從 packages/devtools/.../LGFFJRYV.js 中的 inspect overlay 元件開始,追蹤 click handler 及其 highlight 狀態 effect。接著檢查 packages/devtools-vite/src/utils.ts 中無效的 open-source 請求。完成標準是 click-to-source 保留 data-tsd-source 值、成功開啟編輯器,且格式錯誤的請求收到已完成的 400 回應,而不是一直掛起。
由索引模型根據 Issue 內容生成。
描述
TanStack Devtools version
@tanstack/devtools-vite: 0.7.0 @tanstack/react-devtools: 0.10.5
Framework/Library version
react: 19.2.6
Describe the bug and the steps to reproduce it
When using the inspect hotkey (Shift+Alt+Cmd) to click a component, the request to `/__tsd/open-source?source=` is
sent with an empty source parameter, even though the clicked element has a valid data-tsd-source
attribute. The dev server then hangs the request indefinitely, so the editor never opens.
This is fully reproducible in any React app using @tanstack/[email protected] (which pulls in
@tanstack/[email protected]) + @tanstack/[email protected]. I am seeing it across multiple projects with
similar stacks.
Versions
@tanstack/[email protected]@tanstack/[email protected]@tanstack/[email protected][email protected],[email protected], Solid (bundled via devtools)
Reproduction
- Add
@tanstack/devtools-viteto a Vite + React project with a configurededitor. - Mount
<TanStackDevtools>in the app. - Hold Shift+Alt+Cmd and click any rendered component.
- Observed: Network panel shows
GET /__tsd/open-source?source=(empty value), statuspendingforever.
Editor never opens. - Expected: URL should include the clicked element's
data-tsd-source, server should respond200, editor
should open.
I verified the clicked element has a well-formed data-tsd-source attribute (matching /^\/.+:\d+:\d+$/). On the
page tested there were 1869 such elements, 0 empty, 0 malformed.
Root cause
packages/devtools/src/.../LGFFJRYV.js (the inspect overlay component) registers this click handler:
createEventListener(document, "click", (e) => {
if (!highlightState.element) return;
window.getSelection()?.removeAllRanges();
e.preventDefault();
e.stopPropagation();
setDisabledAfterClick(true); // <-- step 1
if (settings().sourceAction === "copy-path") {
navigator.clipboard.writeText(highlightState.dataSource).catch(() => {});
return;
}
const baseUrl = new URL(import.meta.env?.BASE_URL ?? "/", location.origin);
const url = new URL(
`__tsd/open-source?source=${encodeURIComponent(highlightState.dataSource)}`, // <-- step 2
baseUrl
);
fetch(url).catch(() => {});
});
setDisabledAfterClick(true) flips this memo:
const isActive = createMemo(
() => isHighlightingKeysHeld() && !disabledAfterClick()
);
…which makes isActive() false, which synchronously re-runs the highlight createEffect:
createEffect(() => {
if (!isActive()) {
resetHighlight(); // <-- sets element=null, dataSource=""
return;
}
...
});
By the time the next line in the click handler reads highlightState.dataSource, it is "". The constructed URL
is /__tsd/open-source?source= and is sent.
Compounding server-side bug
In @tanstack/devtools-vite (utils.js), the middleware does:
if (req.url?.includes("__tsd/open-source")) {
const source = new URLSearchParams(req.url.split("?")[1]).get("source");
if (!source) return; // <-- leaves the response hanging
const parsed = parseOpenSourceParam(source);
if (!parsed) return; // <-- same
...
}
Both early returns omit both res.end() and next(), so the connection sits open until the browser times out.
This is why users see "pending" rather than a quick failure.
Evidence
Captured at click time on a component whose data-tsd-source attribute is
/src/routes/tournaments/$tournament_id/leaderboard.tsx:55:7:
{
"url": "http://localhost:5173/__tsd/open-source?source=",
"rawSource": "",
"stack": "...at HTMLDocument.<anonymous> (LGFFJRYV-DaE8v0zr.js:6195:3)"
}
reqid=101 GET http://localhost:5173/__tsd/open-source?source= [pending] in the Network panel.
The clicked element under the cursor at the same instant:
{ tag: "H1", src: "/src/routes/tournaments/$tournament_id/leaderboard.tsx:55:7" }
Suggested fix
Client (packages/devtools/.../LGFFJRYV.js): capture dataSource before mutating signals.
createEventListener(document, "click", (e) => {
if (!highlightState.element) return;
+ const source = highlightState.dataSource; // capture before any setSignal
window.getSelection()?.removeAllRanges();
e.preventDefault();
e.stopPropagation();
- setDisabledAfterClick(true);
if (settings().sourceAction === "copy-path") {
- navigator.clipboard.writeText(highlightState.dataSource).catch(() => {});
+ navigator.clipboard.writeText(source).catch(() => {});
+ setDisabledAfterClick(true);
return;
}
const baseUrl = new URL(import.meta.env?.BASE_URL ?? "/", location.origin);
- const url = new URL(`__tsd/open-source?source=${encodeURIComponent(highlightState.dataSource)}`, baseUrl);
+ const url = new URL(`__tsd/open-source?source=${encodeURIComponent(source)}`, baseUrl);
fetch(url).catch(() => {});
+ setDisabledAfterClick(true);
});
Wrapping the signal write in batch(() => setDisabledAfterClick(true)) would not help here — the read happens
after the write, so the value is already reset by the time we read.
Server (packages/devtools-vite/src/utils.ts): defensively end the response on bad input instead of leaving
the socket open.
if (req.url?.includes("__tsd/open-source")) {
const source = new URLSearchParams(req.url.split("?")[1]).get("source");
- if (!source) return;
+ if (!source) { res.statusCode = 400; res.end(); return; }
const parsed = parseOpenSourceParam(source);
- if (!parsed) return;
+ if (!parsed) { res.statusCode = 400; res.end(); return; }
...
}
Workaround for users until fixed
Add this to your client entry (e.g., src/main.tsx) in dev only:
if (import.meta.env.DEV) {
let lastSource: string | null = null;
document.addEventListener('click', (e) => {
if (e.shiftKey && e.altKey && (e.metaKey || e.ctrlKey)) {
const t = document.elementFromPoint(e.clientX, e.clientY);
const el = t?.closest?.('[data-tsd-source]') as HTMLElement | null;
if (el) lastSource = el.getAttribute('data-tsd-source');
}
}, true); // capture phase: runs before the buggy handler
const orig = window.fetch;
window.fetch = function(input, init) {
const url = typeof input === 'string' ? input
: input instanceof URL ? input.href
: (input as Request).url;
if (typeof url === 'string' && url.endsWith('/__tsd/open-source?source=') && lastSource) {
const fixed = url + encodeURIComponent(lastSource);
lastSource = null;
return orig.call(this, fixed, init);
}
return orig.call(this, input, init);
};
}
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
A minimal sandbox isn't practical for this bug.
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Maybe, I'll investigate and start debugging
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要語言
- TypeScript
- 星號
- 501
- 分支
- 101
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 4
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/devtools 的其他 Issue
-
`intent` bin conflicts with @tanstack/intent and imports removed subpath可能已有人在做 @AlemTuzlak 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
-
devtools-ui 0.7.0 breaks SSR boot with solid-js <=1.9.12: `use` is not exported by solid-js/web server build可能已有人在做 @AlemTuzlak 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
-
data-tsd-source inject-source plugin causes hydration mismatch in SSR (TanStack Start)可能已有人在做 @AlemTuzlak 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
-
Pre-bundled client ignores the event bus port from devtools-vite可能已有人在做 @AlemTuzlak 於 3 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 52/100
查看 TanStack/devtools 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
bug:new
難度 2/5 1-3 小時 新手友好度 76/100
callstackincubator/simlock#350 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
openwatersio/maritime-zones#33 ·
維護者通常 1 天內回覆
-
Booking email verification fails for plus aliases with impersonation protection enabled可能已有人在做 @kankadev 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 88/100
calcom/cal.diy#30293 · 1 則留言 ·
維護者通常 5 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
AOSSIE-Org/DebateAI#611 ·
維護者通常 3 天內回覆