Next.js: Inconsistent loading order of CSS in dev mode

Created on 16 Apr 2020  路  15Comments  路  Source: vercel/next.js

Bug report

Describe the bug

It's based on https://github.com/zeit/next.js/issues/10148#issuecomment-614478653. When _app.jsx contains component which imports postcss module the order of css chunks is inconsistent. Most likely css from module is inserted before global css.

To Reproduce

I created a repo for you https://github.com/Joozty/nextjs-css. It's a fork from https://github.com/zeit/next.js/issues/10148. So the steps to reproduce are almost identical.

Expected behavior

CSS in dev mode should be imported/inserted the same way as on production, i.e. global css first and then modules.

Thanks a lot :)

bug p1

Most helpful comment

This should be fixed in ^9.3.6-canary.9!

I'm installed the exact version 9.3.6-canary.9 and unfortunately in production mode there are still duplicate css.

I'm using sass, but I don't think that could be the problem.

All 15 comments

I still have problems with css order too.
I think the comment below is the same problem :thinking:

https://github.com/zeit/next.js/pull/11901#issuecomment-614644961

Maybe I have a similar bug:

  1. I am using Dart SASS: "node-sass": "npm:[email protected]" with @use imports.
  2. Also I am using CSS Modules.
  3. And I tried both Next.js built-in CSS and @zein/next-css with custom config,
  4. Everything works just perfect in development.
  5. But I have a problems with styles in production: some elements displaying not correctly because of different CSS-files importing order or because CSS duplicates (there is no duplicates in dev).

Production (button is visible - its mistake):
prod

Development (button is hidden - its correct):
dev

Just no ideas, how to fix it...

And also there is such a strange thing: styles duplicates appears after HOVERing over the button...
Production:
simple
Production (after hover)
hover

I am installed this version v9.3.6-canary.0 because has a patch to fix css, but didnt resolve to me.

I dont really what it that, but i continuous having duplicates between css chunks and when not, problems with classes order/priority.

@fabinppk, hello.
I think v9.3.6-canary.0 fixes other problems "Correct Global and Local CSS Loading Order in Dev". No words about avoiding duplicates. And I have no problems is dev, only in production :(

I understand, but the v9.3.6-canary.0 brokers my css in dev mode too, not only in production.

Maybe I have a similar bug:

1. I am using Dart SASS: `"node-sass": "npm:[email protected]"` with `@use` imports.

2. Also I am using CSS Modules.

3. And I tried both Next.js built-in CSS and `@zein/next-css` with custom config,

4. Everything works just perfect in development.

5. But I have a problems with styles in production: some elements displaying not correctly because of different CSS-files importing order or because CSS duplicates (there is no duplicates in dev).

Production (button is visible - its mistake):
prod

Development (button is hidden - its correct):
dev

Just no ideas, how to fix it...

And also there is such a strange thing: styles duplicates appears after HOVERing over the button...
Production:
simple
Production (after hover)
hover

I also have the same issue @iksent, were you able to solve this thing ?

@ashfaqnisar, no, I鈥檓 not. And this is a really big problem...

Yup, all the important css components in the production are broken due to this thing. Can we assign a label to this issue @iksent @Joozty

This should be fixed in ^9.3.6-canary.9!

This should be fixed in ^9.3.6-canary.9!

I'm installed the exact version 9.3.6-canary.9 and unfortunately in production mode there are still duplicate css.

I'm using sass, but I don't think that could be the problem.

Yes, my problem has not been resolved either.
Should we open a new issue, @Timer?
Or maybe move to there: https://github.com/zeit/next.js/issues/12099

I just upgraded to the stable 9.3.6 and I'm still getting global CSS overrriding CSS from modules (see image below). elements.css is imported in the _app.js

image

@bravokiloecho, probably, that's because this issue was resolved in 9.3.6-canary.9
(https://github.com/zeit/next.js/issues/11946#issuecomment-617827900)

@iksent but 9.3.6 was released 7 days after 9.3.6-canary.9 so I assumed it would include everything from that release.

@bravokiloecho, yes. sorry, my mistake.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knipferrc picture knipferrc  路  3Comments

DvirSh picture DvirSh  路  3Comments

wagerfield picture wagerfield  路  3Comments

YarivGilad picture YarivGilad  路  3Comments

jesselee34 picture jesselee34  路  3Comments