Skip to content
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

Turbopack incorrect css modules load order when consuming external components #68412

Closed
bruno12mota opened this issue Aug 1, 2024 · 6 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Module Resolution Module resolution (CJS / ESM, module resolving). Turbopack Related to Turbopack with Next.js.

Comments

@bruno12mota
Copy link

Link to the code that reproduces this issue

https://github.com/bruno12mota/next-styles-order

To Reproduce

  1. pnpm i
  2. Start app pnpm dev
  3. Open app http://localhost:3000/

Current vs. Expected behavior

CSS modules styles are applying in an incorrect order when consuming external components.

On this particular example, I'm expecting that the styles.differentBg is applied with higher priority than the styles applied to LinkButton component on its styles since it's being imported before.

Here's the order of applied styles I'm getting:

Screenshot 2024-08-01 at 19 11 08

As you can see differentBg is coming before styles imported in the LinkButton component. This seems to happen only for external components since I've also included a LocalButton that is doing the same thing but has the styles applied in the correct order:

Screenshot 2024-08-01 at 19 17 45

All of this works correctly if not running with turbo.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 18.20.4
  npm: 10.7.0
  Yarn: N/A
  pnpm: 7.33.6
Relevant Packages:
  next: 15.0.0-canary.96 // Latest available version is detected (15.0.0-canary.96).
  eslint-config-next: N/A
  react: 19.0.0-rc-3208e73e-20240730
  react-dom: 19.0.0-rc-3208e73e-20240730
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Module Resolution, Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

@bruno12mota bruno12mota added the bug Issue was opened via the bug report template. label Aug 1, 2024
@github-actions github-actions bot added Module Resolution Module resolution (CJS / ESM, module resolving). Turbopack Related to Turbopack with Next.js. labels Aug 1, 2024
@samcx samcx changed the title Turbo incorrect css modules load order Turbopack incorrect css modules load order when consuming external components Aug 7, 2024
@samcx
Copy link
Member

samcx commented Aug 7, 2024

@bruno12mota Thank you for submitting an issue!

Interesting it's not working with that particular external component. I'll share this with the team!

@github-actions github-actions bot added the linear: next Confirmed issue that is tracked by the Next.js team. label Aug 12, 2024
@joelwhalar
Copy link

joelwhalar commented Aug 14, 2024

@samcx I have exactly the same issue, we are consuming our component library in the consumer project, the component library uses css modules same as the consumer project, but the styles from the external library are at the bottom of the generated css file wish makes them more specific than the local styles from the consumer project.

I have started testing since when this is happening, seems the bug was introduced in 14.2.0 it works for me in 14.1.1. I also tested 14.2.5 wish where I originally detected the issue.

Generated DEV CSS Files:
14.1.1:
page-14.1.1.txt

14.2.0:
page-14.2.0.txt

@timneutkens timneutkens added linear: turbopack Confirmed issue that is tracked by the Turbopack team. and removed linear: next Confirmed issue that is tracked by the Next.js team. labels Aug 19, 2024
@github-actions github-actions bot added the linear: next Confirmed issue that is tracked by the Next.js team. label Aug 19, 2024
@bruno12mota
Copy link
Author

Still not working on 15.0.0-canary.135.

Would be great to know if this is something being worked on right now or if we should find out an alternative solution.

@timneutkens
Copy link
Member

It's been triaged and it's being worked on.

@bruno12mota
Copy link
Author

Closing since this seems to be fixed, thanks!

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Module Resolution Module resolution (CJS / ESM, module resolving). Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

4 participants