next.js: Updating CSS Modules always triggers full reload
Link to the code that reproduces this issue
https://github.com/vercel/next.js/tree/canary/packages/create-next-app
To Reproduce
-
Install Next.js app by
npx create-next-app@latest -
Select each options for installation like this.
-
Update
app/page.module.cssand it triggers full reload instead of fast refresh like this
Current vs. Expected behavior
It should trigger fast refresh when I edit css modules. Actually, the following cases execute fast refresh correctly.
- When I edit a native css file (like global.css)
- When I didn’t choose
App Routerat the install.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 23.0.0
Binaries:
Node: 18.11.0
npm: 10.2.1
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 13.5.6
eslint-config-next: 13.5.6
react: 18.2.0
react-dom: 18.2.0
typescript: 5.2.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router, CLI (create-next-app)
Additional context
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 24
- Comments: 15 (2 by maintainers)
I’ve had this bug for months and I finally figured out what causes this!! but there’s still no fix. It happens if you have a css module file in a server component.
If you convert the component or page using the css module file to a client component with ‘use client’ and then go back to the module css file and save the smooth hot reload will work again.
This is very frustrating because I have many server components that use css modules that I don’t necessarily want to convert to client components.
This bug really slows down productivity for those who use CSS modules with server components!
Hi everyone—
I can confirm this is still an issue with Webpack HMR.
Have you folks tried using Turbopack instead (highly recommend at this point as dev is passing all tests). With Turbopack (
next dev --turbo), this is not an issue.Any updates from the team on this one? Been encountering the same issue here across multiple projects for quite a while now. It seems to be a pretty long-standing issue, and it’s a serious productivity killer – especially on slower machines or when a route requires network calls each time it loads.
Same problem here on next@14.0.4
Any changes inside a stylesheet module file (any.module.scss) will cause a page reload.
I can confirm the issue still persists on 15.0.1. Temp solution while working with styles is to mark (if possible, of course) the component that’s importing the scss module as a client component - that’s the only way not to trigger the full reload.
Apart from this temp fix, I’ve noticed that the behavior is super unpredictable with regards to the full reload, as sometimes removing all components included in the page and then adding them back fixes the reload issue for a minute or so, then, without any other changes it comes back. Super frustrating. Too bad I’m not able to use turbo yet (working with Payload CMS, which still hasn’t adopted turbo completely).
Edit: Turbo seems to work. Not helpful for this issue, though. There are still lots of people who can’t use turbo yet.