vite-plugin-vue icon indicating copy to clipboard operation
vite-plugin-vue copied to clipboard

HMR doesn't work when using `useCssModule` with SSR

Open rvfakie opened this issue 1 year ago • 6 comments

Describe the bug

Bug with HMR, CSS Modules and SCSS mixins imported with vite.

Please see reproduction and link to issue in nuxt. @danielroe has also managed to reproduce this bug. I've attached his reproduction link.

After updating imported scss mixin in _buttons.scss styles for <button> just disappear. Try to edit _buttons.scss style properties and you will see default button styles after HMR.

But if you modify app.vue after modifying _buttons.scss you will see HMR working correct.

Reproduction

https://stackblitz.com/edit/github-cbd5fr?file=vite.config.js

Steps to reproduce

No response

System Info

System:
    OS: macOS 13.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 116.52 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.1/bin/npm
  Browsers:
    Chrome: 111.0.5563.146
    Safari: 16.2

Used Package Manager

npm

Logs

No response

Validations

rvfakie avatar Apr 05 '23 14:04 rvfakie

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

stackblitz[bot] avatar Apr 05 '23 14:04 stackblitz[bot]

It seems SCSS is not necessary to reproduce.

It doesn't work when editing CSS module styles + using useCssModule + SSR. https://stackblitz.com/edit/github-cbd5fr-qeqagm?file=src%2Fmain.ts,src%2FApp.vue

sapphi-red avatar Apr 06 '23 03:04 sapphi-red

Hello! If it only reproduce in ssr mode, is it possible to solve this problem?

Lustach avatar Oct 24 '23 11:10 Lustach

I'm experiencing the same issue. I'm using Nuxt (for context) with <style module lang="scss"> in SFCs. When I update my mixin.scss file in ./assets, all custom styles are removed from the target element, except for the reset I also apply from the same file, interestingly enough). Neither soft nor hard browser reloads will resolve the issue. I need to completely restart the server to resolve it. Editing app.vue as @rvfakie mentioned also works and saves time, but it would be great to see a more robust fix for this.

kier-mc avatar Jun 20 '24 11:06 kier-mc

Same here. Nuxt. but im not editing mixins like in comment above, im editing scss module. Also, to reproduce: after page load change something in vue file, save, then change scss module > there you go, html class names stay same but in styles they changed.



Neoniq avatar Jul 18 '24 14:07 Neoniq

Exact same issue here.

When i change and save a file thats imported into my main.scss, the hmr wont update despite the terminal saying the hmr has updated.

Whenever i then save the main.scss, the styles on the frontend actually get updated, really need a fix for this

Matheun avatar Jul 18 '24 15:07 Matheun