Repository navigation
Closed as duplicate
Labels
duplicateThis issue or pull request already exists
Description
Describe the bug
When using addWatchFile(…) inside a transform hook on CSS files, the watched files will successfully trigger a rebuild of the CSS file whenever they change.
However, a rebuild triggered from the watched files will always cause a hard-refresh instead of a HMR refresh of the Stylesheet that happens when the CSS file changes on it's own.
This can be reproduced by a plugin like this:
function plugin(): Plugin {
return {
name: "my-plugin",
async transform(content: string | undefined, id: string) {
if (id.endsWith("main.css")) {
this.addWatchFile(
fileURLToPath(new URL("./articles/test.txt", import.meta.url))
);
return `/* ${Math.random()} */\n${content}`;
}
},
};
}In Tailwind CSS, we use addWatchFile(…) extensively to avoid setting up our own watchers.
Reproduction
https://github.com/philipp-spiess/vite-css-dependency-hard-refresh
Steps to reproduce
pnpm build
pnpm vite dev
touch src/index.css # This triggers a HMR
touch artilces/test.txt # This triggers a hard-refreshSystem Info
System:
OS: macOS 15.3.1
CPU: (16) arm64 Apple M4 Max
Memory: 168.77 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.11.0 - ~/.local/share/mise/installs/node/22.11.0/bin/node
Yarn: 1.22.22 - ~/.local/share/mise/installs/node/22.11.0/bin/yarn
npm: 10.9.0 - ~/.local/share/mise/installs/node/22.11.0/bin/npm
pnpm: 9.14.4 - ~/.local/share/mise/installs/pnpm/9.14.4/bin/pnpm
bun: 1.1.34 - ~/.local/share/mise/installs/bun/1.1.34/bin/bun
Browsers:
Brave Browser: 133.1.75.180
Chrome: 133.0.6943.127
Safari: 18.3
Safari Technology Preview: 18.2
npmPackages:
vite: ^6.2.0 => 6.2.0Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already exists
Activity