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
Styles duplicated across css chunks create source order issues #12343
Comments
I am having exactly the same problem: #11946 (comment) |
Same problem here too 😢 |
Any progress? I still have the same problem and I can't put it into production. |
@EduardoPedrosa |
We seem to be having a similar problem with components from a shared component library in our monorepo - any styles in our app that affect those components are overridden by the library styles, despite the fact that the specificity of the styles in our app CSS files is higher and therefore should take precedence. It looks fine in dev mode, just not production :( (We are using SCSS modules with |
When i was using @zeit/next-sass or @zeit/next-css everything was pretty fine with order, preference and duplicates between chuncks. 🤔 The real problem to me begins when i updated nextjs to 9.3 and started using css modules. |
I tried both 2 methods (next-sass and built-in) - the problem existed in both cases |
My Stack:
Tried a lot of variations and this one works for me (having no styles duplicates):
index.scss:
It will be great, if someone try such a configuration, so I can make sure this really works. |
I suggest replacing this: .other-page__component-override { background: pink; } With this: .other-page .component-override { background: pink; } So the page-specific styles only apply on that specific page =). |
I'm having trouble with this bug too. |
I use next 9.4.4 with built-in css support and I have this problem too, it happens in production. |
Same problem on next 9.4.4. Only in production mode |
This happens to our production env on next 9.4.4, and somehow we found a solution. As using
Reference: outputStyle After checking css classname after |
Thanks for sharing @Howard86, tried but it didn't work here. We are using next-css and next-sass on our builds also (not the built-in CSS support from next, and having the same problem described in this issue), and the duplication occurs in classes coming from pure css imported as css-modules, which not come from sass styles |
I am using built-in CSS from next, next 9.4.4 and your solution also dont worked to me. 😢 |
This bug makes using css-modules in next.js impossible (cause no one wants to add !important in styles) |
You can bump up specificity for the styles that override the basic styles. For instance, let's have components dependency as Button <- IconButton <- MoreSpecificButton. In this case, Button has its own styles that get reloaded when switching to another page and therefore overrides styles from IconButton and MoreSpecificButton. If IconButton has its styles defined as |
I am experiencing the same issue. |
+1 with Tailwind, Bootstrap. Current workaround is to import all the styles via link rel in the _document.js. For Tailwind it is custom css build. This problem is very annoying. |
I'm using css modules with tailwind (normal global css import). Inlining css solved the load ordering, but I don't know if it is still duplicating, it's just a workaround. In production, I didn't notice a style overriding another. |
This is fixed on the latest Next.js canary. Please upgrade to |
Doesn't fix it for me, as an example, line heights, font weights, background colors, borders are different in dev and prod. |
@talaikis please open a new issue with a fully reproducible demo then! I've tested the exact code given in this reproduction and its working on |
Fix to me, but it causes another more critical problem. |
Can you please try |
@Timer running |
@fabinppk please open a new issue with a reproduction! |
Just wanted to confirm the original issue seems to be fixed in |
Thanks for confirming @petewarman! |
@Timer sure. I think your fix its ok and its not related with this problem in devtools. |
Can confirm this is still happening with |
@glottonous all problems commented in this issues was solved by timer. Ps: i am using 9.5.5. 👌👌 |
@fabinppk I can confirm that the same issue is still happening as of |
@glottonous I did some tests on my project with version If you are really having a problem, open a new issue by referencing this one. 👍 |
in nextjs 10, same issues |
Same issues 10.0.1 |
I've started #19055 with a reproducible demo. |
Bug report
Describe the bug
I have an application that uses a component on multiple pages. When I build the project that component's styles are duplicated in each of the relevant css page chunks; this creates visual bugs.
For example (
some-component
, andinitial-page-component-override
are classes applied to the same element in the DOM on the initial page):initial-page.chunk.css
second-page.chunk.css
When second-page.chunk.css is added to the DOM the component styles are reapplied over the top of any page specific styles defined in the initial page. The overrides are lost and the incorrect margin is now applied to the component on the initial page. N.B. this is not an issue in dev mode, only in production.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
npm i
,npm run build
,npm start
Expected behavior
Style declarations should not be duplicated in compiled stylesheets. Component styles should loaded (in their own chunk?) above page specific styles.
System information
The text was updated successfully, but these errors were encountered: