-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: prevent unnecessary reloads #8356
base: main
Are you sure you want to change the base?
Conversation
I guess changing if (!hmrContext.modules.length) {
// html file cannot be hot updated
if (file.endsWith('.html')) {
config.logger.info(colors.green(`page reload `) + colors.dim(shortFile), {
clear: true,
timestamp: true
})
ws.send({
type: 'full-reload',
path: config.server.middlewareMode
? '*'
: '/' + normalizePath(path.relative(config.root, file))
})
} else {
// loaded but not in the module graph, probably not js
debugHmr(`[no modules matched] ${colors.dim(shortFile)}`)
}
return
} to // html file cannot be hot updated
if (file.endsWith('.html')) {
config.logger.info(colors.green(`page reload `) + colors.dim(shortFile), {
clear: true,
timestamp: true
})
ws.send({
type: 'full-reload',
path: config.server.middlewareMode
? '*'
: '/' + normalizePath(path.relative(config.root, file))
})
return
}
if (!hmrContext.modules.length) {
// loaded but not in the module graph, probably not js
debugHmr(`[no modules matched] ${colors.dim(shortFile)}`)
return
} is better. (I'm not sure if I'm correct.) |
I'm running into a slightly different issue, but the fix is the same. Is there a good reason not to add the path that caused the full-reload to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current PR is fine by me, but probably be safer if we do it like this too:
vite/packages/vite/src/node/server/hmr.ts
Lines 203 to 208 in c3b3d3c
hot.send({ | |
type: 'full-reload', | |
path: config.server.middlewareMode | |
? '*' | |
: '/' + normalizePath(path.relative(config.root, file)), | |
}) |
Regarding sapphi's comment, I suppose if the HTML was ever in the hmrContext.modules
, it may be safer to invalidate the modules anyway to prevent potential issues with tailwind.
With the updated understanding over the last two years, I agree with that. 😅 |
Description
I'm working on a Tailwind project, when I update an
html
file that is tracked by Tailwind, Vite full-reloads all pages.If files are tracked by Tailwind they bypass this check:
vite/packages/vite/src/node/server/hmr.ts
Line 105 in a9ccedd
In my case,
hmrContext.modules
is:hmrContext.modules
When they bypass here, they fall into here:
vite/packages/vite/src/node/server/hmr.ts
Lines 164 to 171 in a9ccedd
Which is the source of problem. This part of code doesn't send
path
to full-reload events and this cause full reload on all pages:vite/packages/vite/src/client/client.ts
Lines 116 to 131 in a9ccedd
I assume this is what happened to @cdauth, as he described in #6695:
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).