question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
nstfkccommented, Feb 1, 2020

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.

4reactions
Exelordcommented, Feb 5, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should global css be put in each component or the root ...
I'd import your font.css file when and where you use it (but not exactly the way you suggest, see below) and not just...
Read more >
Global vs. Local Styling In Next.js - Smashing Magazine
The answer is surprisingly simple — to write well-structured CSS that balances global and local styling concerns.
Read more >
Styling in React: 5 ways to style React apps - LogRocket Blog
Learn about styling React components with inline styling, styled-components, CSS modules, Tailwind CSS, and Sass and CSS style sheets.
Read more >
Working with CSS in Nuxt.js - Red Onion
Main topics in this article are preprocessors, autoprefixing, CSS Source Maps , global styles and how to add a separate CSS file to...
Read more >
How to add stylesheet in Next.js ? - GeeksforGeeks
In this post, we have used all the CSS files present in styles folder, components/Navbar.js, pages/_app.js and pages/index.js. Syntax: To import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found