Next.js: Bug: Global styles included in _app.js are placing at the end of <head>

Created on 31 Jan 2020  路  7Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Global styles included in _app.js are placed at the end of head tag. They can overwrite component styles.

To Reproduce

Just import any global styles in _app.js and they will appear at the end of head tag.

Expected behavior

I expected to see the next appearing order of head tags in next.js:

  1. Tags included in _document.js (works 馃憤)
  2. Tags included in _app.js (works 馃憤)
  3. Global styles included in _app.js (not working 馃槨)
  4. Tags of pages (works 馃憤)

Screenshots

image
image

  • OS: [macOS]
  • Version of Next.js: [9.2.1]
needs investigation

Most helpful comment

This also conflicts with sass imports and compilation order. Inside of modules you are not able to use variables defined in globals styles.

All 7 comments

Global styles should be placed in _document, especially something like normalize.css. On the other hand it's next/head expected behavior, adds tags end of the tags in document head. Can you elaborate why you want to achieve this.

Next.js says what if you wanna place global styles then place it in _app.js. If you try to do that in another place (in _docmuent.js or in custom HOC wrapper), then it will print CSS cannot be imported within pages/_document.js. Please move global styles to pages/_app.js.
image

So you are not right with:

Global styles should be placed in _document

Global styles should be placed in _app.js

And global styles should be above non-global styles. It is obvious for everyone who developed something.

I already answer for that:

Can you elaborate why you want to achieve this.

You can check the first message. I repeat one more time:
Otherwise, the global styles will overwrite the component styles, which should not be. For example, if I wanna overwrite some global css variables. With current behavior it's impossible.

P.S. And it is not next/head expected behavior. Bcs next/head works correctly everywhere. It is only global styles expected behavior

P.P.S. I apologize for micro-aggression, but it is frustrating that I have to explain such simple truths.

@timneutkens any thoughts?

This also conflicts with sass imports and compilation order. Inside of modules you are not able to use variables defined in globals styles.

Is this the same issue as https://github.com/zeit/next.js/issues/8534? Wondering if #11901 also fixes the issue I was having

Was this page helpful?
0 / 5 - 0 ratings