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

feat(hmr): reload when HTML file is created/deleted #16288

Merged
merged 4 commits into from
Mar 27, 2024
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
Prev Previous commit
Next Next commit
refactor(hmr): remove configOnly parameter
  • Loading branch information
sapphi-red committed Mar 27, 2024
commit de606d402818f2d575c69b4041515c39a8ffd119
5 changes: 0 additions & 5 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export async function handleHMRUpdate(
type: 'create' | 'delete' | 'update',
file: string,
server: ViteDevServer,
configOnly: boolean,
): Promise<void> {
const { hot, config, moduleGraph } = server
const shortFile = getShortName(file, config.root)
Expand Down Expand Up @@ -151,10 +150,6 @@ export async function handleHMRUpdate(
return
}

if (configOnly) {
return
}

debugHmr?.(`[file change] ${colors.dim(shortFile)}`)

// (dev only) the client itself cannot be hot updated.
Expand Down
7 changes: 3 additions & 4 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,10 @@ export async function _createServer(
const onHMRUpdate = async (
type: 'create' | 'delete' | 'update',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an opportunity to define new names for the new hotUpdate API, so maybe we could discuss what are the best ones here already. I'm good with create, delete, update (Parcel Watcher and others use that). I imagine it is better than add, unlink, change names from Chokidar? But fs.watch in node uses change too, no?
This is a internal type for now, so I'm good with you merging it as is and we can discuss once we need to expose it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aligned these names with the watchChange hook.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, perfect 👍🏼

file: string,
configOnly: boolean,
) => {
if (serverConfig.hmr !== false) {
try {
await handleHMRUpdate(type, file, server, configOnly)
await handleHMRUpdate(type, file, server)
} catch (err) {
hot.send({
type: 'error',
Expand Down Expand Up @@ -766,15 +765,15 @@ export async function _createServer(
}
}
if (isUnlink) moduleGraph.onFileDelete(file)
await onHMRUpdate(isUnlink ? 'delete' : 'create', file, false)
await onHMRUpdate(isUnlink ? 'delete' : 'create', file)
}

watcher.on('change', async (file) => {
file = normalizePath(file)
await container.watchChange(file, { event: 'update' })
// invalidate module graph cache on file change
moduleGraph.onFileChange(file)
await onHMRUpdate('update', file, false)
await onHMRUpdate('update', file)
})

getFsUtils(config).initWatcher?.(watcher)
Expand Down