Skip to content

Commit 30db612

Browse files
committed
fix(devtools): snapshot data-tsd-source before mutating click state
The click handler in SourceInspector called `setDisabledAfterClick(true)` before reading `highlightState.dataSource`. That signal write flipped `isActive` to false, triggering the highlight effect's `resetHighlight()` synchronously enough (via the chained `createStore` reactions) to clear `dataSource` before the subsequent reads. Result: the open-source fetch was issued with `?source=` empty and clipboard writes wrote an empty string. Capture `highlightState.dataSource` into a local before any state mutations, then use the captured value for both the clipboard path and the URL construction.
1 parent 856f02b commit 30db612

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

packages/devtools/src/components/source-inspector.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,25 @@ export const SourceInspector = () => {
9595
createEventListener(document, 'click', (e) => {
9696
if (!highlightState.element) return
9797

98+
// Snapshot the source before any signal writes: setDisabledAfterClick
99+
// below flips isActive, which causes the highlight effect to run
100+
// resetHighlight() and clear dataSource before we reach the reads below.
101+
const source = highlightState.dataSource
102+
98103
window.getSelection()?.removeAllRanges()
99104
e.preventDefault()
100105
e.stopPropagation()
101106
setDisabledAfterClick(true)
102107

103108
if (settings().sourceAction === 'copy-path') {
104-
navigator.clipboard.writeText(highlightState.dataSource).catch(() => {})
109+
navigator.clipboard.writeText(source).catch(() => {})
105110
return
106111
}
107112

108113
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
109114
const baseUrl = new URL(import.meta.env?.BASE_URL ?? '/', location.origin)
110115
const url = new URL(
111-
`__tsd/open-source?source=${encodeURIComponent(
112-
highlightState.dataSource,
113-
)}`,
116+
`__tsd/open-source?source=${encodeURIComponent(source)}`,
114117
baseUrl,
115118
)
116119
fetch(url).catch(() => {})

0 commit comments

Comments
 (0)