Skip to content

Commit

Permalink
fix: respect base when using /__open-in-editor (#11337)
Browse files Browse the repository at this point in the history
fixes #8627
  • Loading branch information
sapphi-red committed Dec 12, 2022
1 parent 45b66f4 commit 8856c2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/vite/src/client/overlay.ts
@@ -1,5 +1,10 @@
import type { ErrorPayload } from 'types/hmrPayload'

// injected by the hmr plugin when served
declare const __BASE__: string

const base = __BASE__ || '/'

// set :host styles to make playwright detect the element as visible
const template = /*html*/ `
<style>
Expand Down Expand Up @@ -188,7 +193,7 @@ export class ErrorOverlay extends HTMLElement {
link.textContent = file
link.className = 'file-link'
link.onclick = () => {
fetch('/__open-in-editor?file=' + encodeURIComponent(file))
fetch(`${base}__open-in-editor?file=` + encodeURIComponent(file))
}
el.appendChild(link)
curIndex += frag.length + file.length
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/clientInjections.ts
Expand Up @@ -50,7 +50,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {

return code
.replace(`__MODE__`, JSON.stringify(config.mode))
.replace(`__BASE__`, JSON.stringify(devBase))
.replace(/__BASE__/g, JSON.stringify(devBase))
.replace(`__DEFINES__`, serializeDefine(config.define || {}))
.replace(`__SERVER_HOST__`, JSON.stringify(serverHost))
.replace(`__HMR_PROTOCOL__`, JSON.stringify(protocol))
Expand Down

0 comments on commit 8856c2e

Please sign in to comment.