-
Notifications
You must be signed in to change notification settings - Fork 26.2k
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
Inconsistent CSS resolution order #64921
Comments
It seems |
@GabenGar Thanks for sharing a |
We are seeing the same issue on The specific example we are seeing is that CSS styles imported into layout.js are overriding CSS styles set in a component level stylesheet even though they have the same CSS specificity and the component CSS should override the layout's CSS. This bug appears to be due to the order that the CSS is included in the final static .css files that are included in the production build. |
@benjitastic What kind of CSS styling are you using in this case (e.g., css modules)? |
No, not modules. Just like this inside the component:
Some more details: In this case layout.js had this at the top: And customTheme.scss had this inside it: That bootstrap file has a css style declared for .btn like this: Then in the component we have an element The expectation is that .filter-pill padding can override .btn padding. But .btn was overriding .filter-pill styles. This was because of the 5 Hard to post a repro since I think you need a project that has enough CSS to result in multiple static CSS files being generated. We reverted back to 14.1.4 and the CSS went back to the correct order. |
I am seeing this issue as well, particularly for global styles as well as styles using css modules. As mentioned in this issue, it only happens in production builds. |
Setting |
Interesting -- I can't find any docs anywhere on the Does anybody know exactly what "strict" css chunking does? |
It does not seem to resolve the issue for us :( |
This comment has been minimized.
This comment has been minimized.
@Netail Thanks for sharing.
I can confirm there are several broken cases with the ordering of CSS, after looking at several
Getting some answers internally to further clarify this—will respond back soon! |
That would be great. We use a design system package and a navigation package which uses the design system package (with some overrides) and the app using the design system, but the overwrites are currently not working on productions. Thus making NextJS kind of unusable currently for us. So the sooner the better 😅 Do you by any chance have a ETA when development on this will happen? |
Can confirm this issue also comes up in a project using Next.js 14.2., Mantine v7.10 components, and css modules. Works fine in development mode, loads incorrectly in production. |
I had a similar issue, where global styles were bundled after component styles. Running dev I never had an issue, only on production. I'm using Next 14.2.2 with App router and SSG. My workaround is only for getting global scss that's imported in layout.js to load ahead of client component scss modules. But perhaps this will be helpful for someone else / debugging the overall issue. In my root layout.js I was importing /global.scss There is an Indeed there was css rules added above the global.scss. After analyzing it seems that the css above my My workaround fix is to make a new client component that imports the styles "use client";
import "@/scss/global.scss";
const GlobalStyles = () => {
return <></>;
};
export default GlobalStyles; and then import that component in my root layout.js import GlobalStyles from "./GlobalStyles";
export default function RootLayout({ children }) {
return (
<html lang="en">
<GlobalStyles />
<body>
{children}
</body>
</html>
);
} This resolved the issues I was getting in dev tools, and also some issues with specificity (component styles were no longer overriding global styles before the workaround). |
@Netail No ETA to share yet, but this issue is definitely high on our plate! |
Link to the code that reproduces this issue
https://github.com/GabenGar/repros/blob/main/nextjs/css-out-of-order/README.md
To Reproduce
Reproduction steps are in the README.md
Current vs. Expected behavior
Current:
Different CSS resolution order between development and production. Before I had weird client vs. render CSS issues, but it looks like they are fixed in 14.2, although they weren't super reproducible before either.
Expected:
Work basically like
pages
router.Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: