diff --git a/packages/vite/src/client/overlay.ts b/packages/vite/src/client/overlay.ts index 9951510f916a30..508eaf7e05bc9e 100644 --- a/packages/vite/src/client/overlay.ts +++ b/packages/vite/src/client/overlay.ts @@ -2,7 +2,9 @@ import type { ErrorPayload } from 'types/hmrPayload' // injected by the hmr plugin when served declare const __BASE__: string +declare const __HMR_CONFIG_NAME__: string +const hmrConfigName = __HMR_CONFIG_NAME__ const base = __BASE__ || '/' // set :host styles to make playwright detect the element as visible @@ -142,7 +144,7 @@ kbd {
Click outside, press Esc key, or fix the code to dismiss.
You can also disable this overlay by setting - server.hmr.overlay to false in vite.config.js. + server.hmr.overlay to false in ${hmrConfigName}.
diff --git a/packages/vite/src/node/plugins/clientInjections.ts b/packages/vite/src/node/plugins/clientInjections.ts index 5ac79c8d14ef8e..2a773542aef58c 100644 --- a/packages/vite/src/node/plugins/clientInjections.ts +++ b/packages/vite/src/node/plugins/clientInjections.ts @@ -35,6 +35,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { const timeout = hmrConfig?.timeout || 30000 const overlay = hmrConfig?.overlay !== false const isHmrServerSpecified = !!hmrConfig?.server + const hmrConfigName = path.basename(config.configFile || 'vite.config.js') // hmr.clientPort -> hmr.port // -> (24678 if middleware mode and HMR server is not specified) -> new URL(import.meta.url).port @@ -65,6 +66,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { const hmrBaseReplacement = escapeReplacement(hmrBase) const hmrTimeoutReplacement = escapeReplacement(timeout) const hmrEnableOverlayReplacement = escapeReplacement(overlay) + const hmrConfigNameReplacement = escapeReplacement(hmrConfigName) injectConfigValues = (code: string) => { return code @@ -79,6 +81,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin { .replace(`__HMR_BASE__`, hmrBaseReplacement) .replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement) .replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement) + .replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement) } }, transform(code, id, options) {