vercel / next.js

The React Framework
https://nextjs.org
MIT License
123.24k stars 26.31k forks source link

Updating CSS Modules always triggers full reload #57046

Open gonshi opened 9 months ago

gonshi commented 9 months ago

Link to the code that reproduces this issue

https://github.com/vercel/next.js/tree/canary/packages/create-next-app

To Reproduce

  1. Install Next.js app by npx create-next-app@latest

  2. Select each options for installation like this.

    スクリーンショット 2023-10-19 19 39 27
  3. Update app/page.module.css and it triggers full reload instead of fast refresh like this ezgif-2-fd370fc814

Current vs. Expected behavior

It should trigger fast refresh when I edit css modules. Actually, the following cases execute fast refresh correctly.

  1. When I edit a native css file (like global.css)
  2. When I didn't choose App Router at the install.

Verify 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

gonshi commented 9 months ago

It seems to work correctly if I downgrade the version of next.js to 13.2

Shubhdeep12 commented 9 months ago

Ideally, this should not happen in production because hot module reload works for the development environment. Correct? @balazsorban44

Can you give some insights here on this module-specific CSS files @balazsorban44

It would be really helpful.

Skippou commented 7 months ago

It may be related to my issue.

Editing any tailwind class or editing the global.css causes a hard reload if a CSS file is imported into the layout.tsx.

https://github.com/vercel/next.js/issues/51162#issuecomment-1808078220

Edit: I have tested it with Next v 13.2, then it works.

Celsiusss commented 7 months ago

I have spent some time narrowing this issue down. Two things are needed for this to happen:

Example component where this happens:

import Link from "next/link";
import styles from "./page.module.css";

export default function Home() {
  return (
    <div className={styles.container}>
      <p>main page</p>
      <Link href="/sub" />
    </div>
  );
}

Editing page.module.css will trigger a full reload.

Here is a minimal reproduction example: https://github.com/Celsiusss/next-css-reload-repro Using next@canary.

oelbaga commented 7 months ago

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!

james-meneses-he commented 6 months ago

Any update on this so far?

Edit by maintainers: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

eduardpauliuc commented 6 months ago

I have spent some time narrowing this issue down. Two things are needed for this to happen:

  • Use CSS modules
  • Use the Link component from next/link

Editing page.module.css will trigger a full reload.

Here is a minimal reproduction example: https://github.com/Celsiusss/next-css-reload-repro Using next@canary.

Ran into the same issue. Image component from next/image also triggers the full page reload, even on a new app created with npx create-next-app@latest.

hiranaguiar commented 5 months ago

Same problem here on next@14.0.4

Any changes inside a stylesheet module file (any.module.scss) will cause a page reload.

sleepdotexe commented 2 weeks ago

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.