Dev server and maybe even HMR support for CSS modules? #710
-
First: many thanks for this great library / framework. I currently am migrating an SSG project to this solution and want to continue using CSS modules. This works fine, as it is already supported by Vite. However, it seems like HMR is "broken" in dev mode at least in my setup. I need to restart the whole dev server to reflect changes in CSS module files. Can anybody else reproduce this? I'd love HMR support for CSS modules, currently even a full page reload doesn't help, only restarting the dev server. I'm hesitant to open this as an issue, seems more like a feature request and I haven't tested this in another project, maybe I have quirks in my setup that cause this problem. Have only searched for issues or discussions containing the term "CSS modules" and didn't find any, so hope this is adequate place to ask. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
Normally changes to Minimal reproduction welcome. I suspect one of your libraries to cause issues.
👍 I'm glad you like it. |
Beta Was this translation helpful? Give feedback.
-
👍 |
Beta Was this translation helpful? Give feedback.
-
I tried to and could not reproduce the issue in your As for my HMR (or full page reload) problem when changing CSS, I tried various changes to your example projecrt and to my buggy project. I could rule out the following causes: My buggy project:
At least removing said plugins (and in the first case changing all paths to relative) did not change the behavior, still have to fully restart the Example project:
My buggy project: I retroactively adapted to your plugin from a different previous approach. Will check directory structure, imports and config files for possible causes and compare to docs&examples. Closing this discussion, if I find the cause and there is an actual issue that someone else might encounter I will comment on the closed issue. |
Beta Was this translation helpful? Give feedback.
-
Well first, could resolve all of my other problems, they were mostly related to me missing to inject CSS of the "geist-ui" component library into the server-rendered template. Interestingly, the problem occurs with one CSS module, but not with another one in the same folder. Debug output of non-working change:
(no more output until next request) Debug output of working change:
It seems like alll changes to CSS modules that are imported in the render tree of the default page template work, but changes to modules imported by other components don't. Import of Import of Will have some time later today and dig deeper into what I'm doing wrong. Also will test again with your example project or a scaffolded project and make sure to add and change a CSS module that is only used in a component imported by some specific page render tree (not by default page). //EDIT: |
Beta Was this translation helpful? Give feedback.
-
Just tried again, couldn't find the actual cause by looking through Vite source, but it turned out that the problem went away as soon as I start using Not a satisfying answer, but I am happy now. Previously used Node ^18 LTS with npm ^9. |
Beta Was this translation helpful? Give feedback.
-
Problem was somewhere else. Came back to my page today, suspect issue was in my |
Beta Was this translation helpful? Give feedback.
Problem was somewhere else.
Came back to my page today, suspect issue was in my
vite-config.d.ts
or somewhere else.Also updated to latest version of
vite-plugin-ssr
.Then switched back to node+npm (LTS versions ^18/^9) as my project is small and I didn't want to use pnpm if not needed.
Could not reproduce HMR issues with CSS modules anymore.