Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect base when using /__open-in-editor #11337

Merged
merged 1 commit into from Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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