-
Notifications
You must be signed in to change notification settings - Fork 375
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
[Bug?]: Edits to CSS modules do not trigger HMR and won't update without a page refresh #1400
Comments
I am seeing this same issue, introduced a little over a week ago. |
@hansoksendahl do you know the last version where it was working? That would help me narrow it down considerably. |
This is a vinxi issue right? Vinxi sends the hmr update to replace the css, classes don't match anymore, styling disappears and reload is required. No sure if there is a way around a reload but here is where to look I think. Edit: Oh... it looks to me as if the return value (empty array) is the problem causing vite to only send the custom event. I will make a PR later. |
This issue is persisting for me still is there an update on what is going on with this? @edivados Thanks in advance |
Downgrading vinxi to 3.10 should temporarily avoid this issue? |
A not so nice temporary fix for this is to customize the class name generator vite uses in the config to only use the file path and class name and ignore the css contents when generating class names. This means that class names don't change when the contents changes, which I believe is whats causing the issues. Example config. import crypto from "crypto"
export default defineConfig({
ssr: true,
vite: {
css: {
modules: {
// Need to generate css module names based on only the file path and class name
// because the dev reloading doesn't work well when classes change when css contents change.
generateScopedName(name, filename, css) {
const hasher = crypto.createHash("sha256")
hasher.update(name + filename)
const hash = hasher.digest().toString("hex");
return `${name}__${hash.substring(0, 16)}`
},
}
}
}
}); There is one problem with this though, it doesn't fix the issue of you adding a new class in the css, as it goes from an empty string to some value and therefore that still requires a page refresh. |
Duplicates
Latest version
Current behavior 😯
When making edits to a .module.css file vite triggers a page reload rather than an hmr. The resulting effect is that saving a change to the module wipes all css from the element it is scoped to until you refresh the page at which point everything updates and displays correctly.
Expected behavior 🤔
Making edits to a css module should trigger hmr and update the styling on the component without requiring a full page refresh
Steps to reproduce 🕹
Steps:
1.Usinc CLI - $ npm init solid@latest
2. Name the project, choose to use solid-start and typescript, choose the basic template, npm install, and finally npm run dev.
3. In the basic template update the counter component to use module styling
3-a. Rename Counter.css -> Counter.module.css
3-b. In Counter.tsx rewrite the import and class to accept module styling:
The text was updated successfully, but these errors were encountered: