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(hmr): improve case sensitivity in file checks and clean up debug output #19223

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
15 changes: 8 additions & 7 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
InvokeSendData,
} from '../../shared/invokeMethods'
import { CLIENT_DIR } from '../constants'
import { createDebugger, normalizePath } from '../utils'
import { createDebugger, normalizePath, hasCorrectCase } from '../utils'
import type { InferCustomEventPayload, ViteDevServer } from '..'
import { getHookHandler } from '../plugins'
import { isCSSRequest } from '../plugins/css'
Expand Down Expand Up @@ -379,18 +379,19 @@ export async function handleHMRUpdate(
): Promise<void> {
const { config } = server
const mixedModuleGraph = ignoreDeprecationWarnings(() => server.moduleGraph)

const environments = Object.values(server.environments)
const shortFile = getShortName(file, config.root)

const isConfig = file === config.configFile
const isConfigDependency = config.configFileDependencies.some(
(name) => file === name,
(name) => name.toLowerCase() === file.toLowerCase(),
)

const isEnv =
config.inlineConfig.envFile !== false &&
getEnvFilesForMode(config.mode, config.envDir).includes(file)
getEnvFilesForMode(config.mode, config.envDir).some(
(envFile) => envFile.toLowerCase() === file.toLowerCase()
)
if (isConfig || isConfigDependency || isEnv) {
// auto restart server
debugHmr?.(`[config change] ${colors.dim(shortFile)}`)
Expand Down Expand Up @@ -701,7 +702,7 @@ export function updateModules(

environment.logger.info(
colors.green(`hmr update `) +
colors.dim([...new Set(updates.map((u) => u.path))].join(', ')),
colors.dim([...new Set(updates.map((u) => u.path))].join(', ')),
{ clear: !afterInvalidation, timestamp: true },
)
hot.send({
Expand Down Expand Up @@ -890,7 +891,7 @@ function isNodeWithinCircularImports(
]
debugHmr(
colors.yellow(`circular imports detected: `) +
importChain.map((m) => colors.dim(m.url)).join(' -> '),
importChain.map((m) => colors.dim(m.url)).join(' -> '),
)
}
return true
Expand Down Expand Up @@ -1071,7 +1072,7 @@ export function normalizeHmrUrl(url: string): string {
function error(pos: number) {
const err = new Error(
`import.meta.hot.accept() can only accept string literals or an ` +
`Array of string literals.`,
`Array of string literals.`,
) as RollupError
err.pos = pos
throw err
Expand Down
Loading