Global CSS Import Order
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
I'm switching from the pages dir to the app dir, and the only thing really causing an issue currently is the order of css imports.
My structure is pretty simple. I have
Looking inside of the layout.css file, I see the files are ordered as follows:
For some reason
(On top of that, I have component module css also being loaded before all of these global styles too-- also a problem.)
To keep it simple though, I think the basic question is how can I force my
My structure is pretty simple. I have
app/layout.tsx, and inside of there I am importing normalize.css from an npm package, plus two local css files:import 'normalize.css/normalize.css';
import '@/styles/globals.css';
import '@/styles/common.css';Looking inside of the layout.css file, I see the files are ordered as follows:
globals.css > common.css > normalize.css.For some reason
normalize.css is always ordered after the other two files, even though I have that import first. If I play around with the order of globals.css and common.css, it does change the relative order between them, but normalize.css is always placed after them regardless of import order.(On top of that, I have component module css also being loaded before all of these global styles too-- also a problem.)
To keep it simple though, I think the basic question is how can I force my
normalize.css to be the first styles on the page?2 Replies
Transvaal lionOP
After some digging, it seems that if a client component is included directly in the layout, it causes all of the css in the layout.css file to be ordered apparently by random.
I've worked around it by removing all client components to an intermediate component that's used by the page.tsx files, not layout.tsx.
This means any client component css will be in page.css and not the layout.css. The page.css will still be ordered randomly, but I only have css modules in there which makes it less of an issue.This leaves a lot to be desired since layouts can't really be taken advantage of, and reduces some effectiveness of the code splitting.
I've worked around it by removing all client components to an intermediate component that's used by the page.tsx files, not layout.tsx.
This means any client component css will be in page.css and not the layout.css. The page.css will still be ordered randomly, but I only have css modules in there which makes it less of an issue.This leaves a lot to be desired since layouts can't really be taken advantage of, and reduces some effectiveness of the code splitting.
West African Lion
Related to; https://github.com/vercel/next.js/issues/51030