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.

makeStyles() declaration location affects css load order

See original GitHub issue

The location of makeStyles() affects the order of css files listed in <head></head> when using Nextjs. This causes issues when base styles override custom styles.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When makeStyles() is declared in index.tsx, styles are properly loaded on the examples below (I added an App bar with MUI Links, not Nextjs Links). The spacing between the links and the button is incorrect in the first Codesandbox, and working properly in the second. The only change is the location of makeStyles(). This repository is forked off of the Nextjs Typescript example.

Broken (makeStyles() is in themes.tsx)

Link: https://codesandbox.io/s/mystifying-bogdan-h4wq7

Demo

Screenshot_2020-08-01 CodeSandbox(1)

CSS Load order

Screenshot at 2020-08-01 12-30-44

Expected Behavior 🤔

makeStyles() should be the last css style to load. create-react-app does not have this issue.

Not broken (makeStyles() is in index.tsx)

Link: https://codesandbox.io/s/distracted-framework-2o9fs

Demo

Screenshot_2020-08-01 CodeSandbox(2)

CSS Load order

Screenshot at 2020-08-01 12-31-03

Steps to Reproduce 🕹

Steps:

  1. Move makeStyles() declaration to the same file that uses it. See above codesandbox links.

Context 🔦

Trying to use a central styles configuration rather than having scattered css.

Your Environment 🌎

tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
Tech Version
Material-UI v4.11.0
React ^16.13.1
Browser FF 79 & Chrome 84
TypeScript 3.9.7
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Aug 1, 2020

@esemeniuc We are in the process of dropping our styling engine to rely on the ones used by the community, we have stopped investment on this part one year ago, I don’t think that it’s worth covering.

0reactions
esemeniuccommented, Aug 1, 2020

Could we document this so it doesn’t cause frustration later?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[v5] CSS injection order is wrong · Issue #24109 · mui/material-ui
I'm using the following pattern in my code, but it doesn't work anymore in v5 (tested with 5.0.0-alpha.20). My custom styles get overwritten ......
Read more >
Material UI css load order - reactjs - Stack Overflow
I am using react with material UI and css modules. Problem is that god knows why, all styling from MUI loads at the...
Read more >
Cascade, specificity, and inheritance - Learn web development
The effect of CSS location ... When you declare CSS in cascade layers, the order of precedence is determined by the order in...
Read more >
Precedence in CSS (When Order of CSS Matters)
All of them contain CSS selectors with the same exact specificity. #3 is the last declared, so it wins the precedence battle. Async...
Read more >
Style library interoperability - Material UI - MUI
To remove the need for !important, you need to change the CSS injection order. Here's a demo of how it can be done...
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