-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
HMR not working for CSS Modules #1127
Comments
It seems like the problem is that Vite isn't setting
The interesting logs showing what I believe to be the issue:
Closing as it seems to be a Vite bug. @wxin627 If you're up for it then dig into this file, I suspect the issue to be somewhere in there. |
got it, thanks! |
Is vitejs/vite#16018 related? |
@brillout I think this is the same issue vitejs/vite#16074 and in the issue they say:
So, Yes I think it is related. I asked for clarification. Do you think a possible workaround for this issue would be to completly disabling server rendering in dev mode? Would this be possible using vike? |
@brillout So it seems Vite has released a 2nd party plugin to fix the issue, https://github.com/privatenumber/vite-css-modules I am trying to get it to work with Vike, but so far no luck. Maybe you have a minute to investigate if this is something vike would need to incorporate at a deeper level? Also see this comment. |
I got a notification on Vite PR comment, so I'm checking in here. I'm not sure if it's fair to say Vite's bug, but it's certainly a Vite SSR limitation where frameworks need to resort to The workaround I experimented on my framework hi-ogawa/vite-plugins#346 is to filter out const config: UserConfig = {
plugins: [
{
name: "hack-css-module-hmr",
handleHotUpdate(ctx) {
// prevent full reload due to non self-accepting css module.
// here only "?direct" module should be filtered out as it doesn't have a parent module.
if (ctx.file.includes("module.css")) {
return ctx.modules.filter((m) => !m.id?.includes("?direct"))
}
},
},
react(),
vike(),
]
} |
@hi-ogawa Thank you for checking in here. I tested the code snippet here https://github.com/snake-py/vike-css-module-hmr and it works. @brillout maybe this would be something we can put into Vike? const fileEndings = [....];
{
name: "hack-css-module-hmr",
handleHotUpdate(ctx) {
// prevent full reload due to non self-accepting css module.
// here only "?direct" module should be filtered out as it doesn't have a parent module.
if (ctx.file.includes("module") && fileEndings.some((ending)=>ctx.file.endsWith(ending)) ) {
return ctx.modules.filter((m) => !m.id?.includes("?direct"))
}
},
}, I`d be willing to help out with the implementation of this! |
@brillout I tested the new tag here https://github.com/snake-py/vike-css-module-hmr and it does not work, anything I am doing wrong here? |
|
Reproduction: https://github.com/brillout/vite-plugin-ssr-mvp.
(Failed reproduction using vanilla Vite with SSR: https://github.com/brillout/vite-bug-hmr-css-modules — it fails to reproduce because it doens't have any
*.module.css?direct
module.)(Vanilla Vite without SSR working example: #261 (comment).)
The text was updated successfully, but these errors were encountered: