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

Duplicated styles creates a source order issue when importing CSS modules from node_modules using next-transpile-modules #12099

Closed
petewarman opened this issue Apr 22, 2020 · 4 comments

Comments

@petewarman
Copy link

petewarman commented Apr 22, 2020

I have a nextjs application that has a dependency on a react component library (a first party library) that uses CSS modules to manage styling. I'm passing that library through next-transpile-modules in my next.config.js as suggested here: https://github.com/zeit/next.js/blob/master/errors/css-modules-npm.md

The problem is that if a component from the library is used on more than one page in my application that library component's styles are duplicated in each pages' generated CSS file. This leads to an unpredictable source order (depending on which page loads first) and therefore visual bugs because of the way the styling cascade works.

To Reproduce

I've created a reduced test case:
Nextjs app: https://github.com/petewarman/nextjs-css-module-issue
Component lib: https://github.com/petewarman/demo-component-lib

  1. checkout the Next app repo and npm i, npm run build and then npm start
  2. visit localhost:3000
  3. notice that the button styles change on hover

What seems to be happening

The shared components styles are duplicated in both the generated files in .next/static/css. When the cursor hovers over the link nextjs prefetches the styles for '/another-page' and adds them to the DOM. This results in an incorrect CSS order like this:

// component lib style (present in the homepage css)
.button { background: black; }

// homepage-specific override styling (present in the homepage css)
.button { background: red; }

// component lib style (present in another-page's css)
.button { background: black; }

Expected behavior

The styles for the shared components should be added to the application above page specific styles, and not be duplicated across pages.

@petewarman petewarman changed the title Source order issue when importing CSS modules from node_modules using next-transpile-modules Duplicated styles creates a source order issue when importing CSS modules from node_modules using next-transpile-modules Apr 23, 2020
@iksent
Copy link

iksent commented Apr 27, 2020

Any updates on this?
Just can't use Next.js in production due to this bug.
My problem: #11946 (comment)
@Timer @timneutkens

@petewarman
Copy link
Author

I've tested against next 9.3.6-canary.16 and the issue still exists. NB this is an issue with production builds so won't be fixed by #11901

@petewarman
Copy link
Author

I've done some further investigation and this issue isn't isn't related to shared component libs or next-transpile-modules. I've created a new issue with a simplified explanation of the problem so will close this one. See #12343

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants