-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
When I modify a source file, Vite always reloads the page instead of using HMR. #16764
Comments
Hey! I think we need to file this as an upstream bug report for Nuxt.js. I am able to reproduce this as soon as you add a transform hook to a CSS file that adds a watch directory. So this currently reproduces the same issue: function debug() {
return {
name: "debug",
transform(content: string, id: string) {
if (id.endsWith("main.css")) {
this.addWatchFile(
"/Users/philipp/dev/nuxt-tailwind-source-reload-everytime/articles/test.txt"
);
return { content: `/* ${Math.random()} */\n${content}` };
}
},
};
} I'm going to clean this up an make an upstream bug report! |
Actually can reproduce this in a plain Vite setup, so this appears to be a Vite thing. |
Filed vitejs/vite#19511 |
So, apparently this is expected behavior for now: vitejs/vite#9512 (comment) We'll do some digging on our side (the Vite extension) to see if we can work around this somehow but I can't make any guarantees :/ |
@philipp-spiess Thank you. I found that for my simple use case, adding an extra simple Vite plugin is sufficient. import type { Plugin } from 'vite'
import path from "node:path"
export default function preventTailwindReload(
directories: string[]
): Plugin {
return {
name: 'vite-prevent-tailwind-reload',
handleHotUpdate({ file, modules }) {
const currentDir = process.cwd();
const relativeDir = path.dirname(path.relative(currentDir, file));
if (directories.includes(relativeDir)) {
return [...modules[0]?.importers ?? [], ...modules.slice(1)]
}
}
}
} Of course, it would be even better if the official Tailwind Vite plugin could completely resolve this issue. |
Yes. Currently, only the contents of |
QQ2025222-15517.mp4
What version of Tailwind CSS are you using?
v4.0.8
What build tool (or framework if it abstracts the build tool) are you using?
Vite 6.1.1
What version of Node.js are you using?
v22.14.0
What browser are you using?
Chrome and Firefox
What operating system are you using?
WSL
Reproduction URL
https://github.com/wcshds/nuxt-tailwind-source-reload-everytime
Describe your issue
I tried to use tailwind v4 in my Nuxt project. I use
@source
to explicitly register source path, but when I modify a source file, Vite always reloads the page instead of only using HMR.The text was updated successfully, but these errors were encountered: