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(client): correctly display the config file name #14160

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/vite/src/client/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import type { ErrorPayload } from 'types/hmrPayload'

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

const isHmrTsConfig = __HMR_IS_TS_CONFIG__
const base = __BASE__ || '/'

// set :host styles to make playwright detect the element as visible
Expand Down Expand Up @@ -142,7 +144,9 @@ kbd {
<div class="tip" part="tip">
Click outside, press <kbd>Esc</kbd> key, or fix the code to dismiss.<br>
You can also disable this overlay by setting
<code part="config-option-name">server.hmr.overlay</code> to <code part="config-option-value">false</code> in <code part="config-file-name">vite.config.js.</code>
<code part="config-option-name">server.hmr.overlay</code> to <code part="config-option-value">false</code> in <code part="config-file-name">vite.config.${
isHmrTsConfig ? 'ts' : 'js'
}.</code>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/node/plugins/clientInjections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 isHmrTsConfig = config.configFile?.endsWith('.ts') || false
btea marked this conversation as resolved.
Show resolved Hide resolved

// hmr.clientPort -> hmr.port
// -> (24678 if middleware mode and HMR server is not specified) -> new URL(import.meta.url).port
Expand Down Expand Up @@ -65,6 +66,7 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {
const hmrBaseReplacement = escapeReplacement(hmrBase)
const hmrTimeoutReplacement = escapeReplacement(timeout)
const hmrEnableOverlayReplacement = escapeReplacement(overlay)
const isTsConfigReplacement = escapeReplacement(isHmrTsConfig)

injectConfigValues = (code: string) => {
return code
Expand All @@ -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_IS_TS_CONFIG__`, isTsConfigReplacement)
}
},
transform(code, id, options) {
Expand Down