Skip to content

Commit bb671a7

Browse files
authored
fix: use location.origin; remove localhost hardcoding (#127)
I was using tanstack devtools on my local machine. During my project, some of my logic depended on hostname, so I usually develop using custom domains. The tools started to break and I investigated and noticed that localhost was hardcoded. DevTools hardcoded {scheme}://localhost:{port} for open-in-editor and related links, which broke in my setup where I routinely develop on custom domains/non-loopback hosts (and also impacts IPv6). This PR replaces the hardcoded origin with location.origin so links respect the actual scheme/host/port in use; it fixed the failures I observed while keeping localhost behavior intact. If this direction makes sense, I’m happy to add tests to prevent regressions.
1 parent 4d7425e commit bb671a7

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

packages/devtools-vite/src/plugin.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const defineDevtoolsConfig = (config: TanStackDevtoolsViteConfig) =>
4444

4545
export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
4646
let port = 5173
47-
let host = 'http'
4847
const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true }
4948
const injectSourceConfig = args?.injectSource ?? { enabled: true }
5049
const bus = new ServerEventBus(args?.eventBusConfig)
@@ -71,9 +70,6 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
7170
{
7271
enforce: 'pre',
7372
name: '@tanstack/devtools:custom-server',
74-
configResolved(config) {
75-
host = config.server.https?.cert ? 'https' : 'http'
76-
},
7773
apply(config) {
7874
// Custom server is only needed in development for piping events to the client
7975
return config.mode === 'development'
@@ -119,15 +115,6 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
119115
}),
120116
)
121117
},
122-
transform(code) {
123-
if (code.includes('__TSD_PORT__')) {
124-
code = code.replace('__TSD_PORT__', String(port))
125-
}
126-
if (code.includes('__TSD_HOST__')) {
127-
code = code.replace('__TSD_HOST__', host)
128-
}
129-
return code
130-
},
131118
},
132119
{
133120
name: '@tanstack/devtools:better-console-logs',

packages/devtools/src/devtools.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ export default function DevTools() {
174174
e.preventDefault()
175175
e.stopPropagation()
176176
fetch(
177-
`__TSD_HOST__://localhost:__TSD_PORT__/__tsd/open-source?source=${encodeURIComponent(dataSource)}`,
177+
`${location.origin}/__tsd/open-source?source=${encodeURIComponent(
178+
dataSource,
179+
)}`,
178180
).catch(() => {})
179181
}
180182
}

0 commit comments

Comments
 (0)