-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
When using App dir, Global CSS seems to get bundled incorrectly #48120
Comments
I'm seeing this while in development. I'm not sure, but seems like the hot reload reorders the css somehow, causing styles to break randomly. |
I don't believe it is the same issue as #48807 as hot reloading itself works fine, and things work as expected in development. I can't say for certain if its the same as #47585 as I am not using link tags for my css, I'm importing them directly into the file. The big issue here is that for me things work completely fine in dev, and issues occur in prod |
I believe this is a #47585 issue. |
An update: This is still happening as of the most recent release |
This PR fixes a couple of categories of CSS issues in App Router, that come from the same root cause. ### 1. Duplicated styles being loaded in different layers This issue has been described in vanilla-extract-css/vanilla-extract#1088 (comment). If a CSS module (or a global CSS) is referenced in multiple layers (e.g. a layout and a page), it will be bundled into multiple CSS assets because each layer is considered as a separate entry. <img width="1141" alt="CleanShot-2023-05-26-GoB9Rhcs@2x" src="https://github.com/vercel/next.js/assets/3676859/8e0f5346-ee64-4553-950a-7fb44f769efc"> As explained in that issue, we have to bundle all CSS modules into one chunk to avoid a big number of requests. ### 2. CSS ordering issues (conflicts) This is likely causing #48120. When the layer-based bundling and ordering logic applies to CSS, it can potentially cause non-deterministic order. In this example, button A in the layout should be in blue. However when button B is imported by the page, button A becomes red. This is an inconsistent experience and can be hard to debug and fix. <img width="1090" alt="CleanShot-2023-05-26-Ar4MN5rP@2x" src="https://github.com/vercel/next.js/assets/3676859/4328d5d7-23af-4c42-bedf-30f8f062d96a">
I'm still seeing this even on yup, I have the following css imports in my root app layout
the two npm modules are combined and moved after the 2 local css files, which are combined themselves. I'm using pnpm if that affects anything, did not see this issue when using yarn. |
This PR fixes a couple of categories of CSS issues in App Router, that come from the same root cause. ### 1. Duplicated styles being loaded in different layers This issue has been described in vanilla-extract-css/vanilla-extract#1088 (comment). If a CSS module (or a global CSS) is referenced in multiple layers (e.g. a layout and a page), it will be bundled into multiple CSS assets because each layer is considered as a separate entry. <img width="1141" alt="CleanShot-2023-05-26-GoB9Rhcs@2x" src="https://github.com/vercel/next.js/assets/3676859/8e0f5346-ee64-4553-950a-7fb44f769efc"> As explained in that issue, we have to bundle all CSS modules into one chunk to avoid a big number of requests. ### 2. CSS ordering issues (conflicts) This is likely causing vercel#48120. When the layer-based bundling and ordering logic applies to CSS, it can potentially cause non-deterministic order. In this example, button A in the layout should be in blue. However when button B is imported by the page, button A becomes red. This is an inconsistent experience and can be hard to debug and fix. <img width="1090" alt="CleanShot-2023-05-26-Ar4MN5rP@2x" src="https://github.com/vercel/next.js/assets/3676859/4328d5d7-23af-4c42-bedf-30f8f062d96a">
I'm experiencing this kind of random ordering of global CSS in 13.5.2. Is this still an issue for anyone, or is there another thread with up-to-date discussion? |
I am experiencing this issue which causes random full-page reloads because HMR (incorrectly) thinks CSS module hashes change between unrelated file changes. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:43 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8112 Binaries: Node: 16.18.0 npm: 8.19.2 Yarn: N/A pnpm: N/A Relevant packages: next: 13.3.1-canary.3 eslint-config-next: 13.2.4 react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue
https://github.com/SamuelQuinones/samtheq.com/tree/main
To Reproduce
Using the above repository
src/app/layout.tsx
to import@fortawesome/fontawesome-svg-core/styles.css
directly, making sure to put it aboveimport "../styles/globals.css";
import "../styles/fa.css";
linesrc/app/experience/page.tsx
file, just havegetExperienceItems
return the following (so you can see data):Describe the Bug
When importing styles from node_modules and local styles as global styles, import order is preserved in development.
Given the following imports in my root layout file:
Using the provided repo, if I navigate to my experience page, notice the size of the icons:
However if i then build the app, and run it the icons are small:
Looking at the Dev tools, it looks like even though my fontawesome import is first - and should therefore be overwritten by the tailwind rule that sets the height and width as it does in development) for some reason when bundling, the css order gets mixed up (this is the prod screenshot):
Expected Behavior
Css order should be consistent across all environments. It is also worth noting that this does not seem to happen when using the pages folder and an
_app.tsx
file.I am able to get around it by using the trick you see in the repo which is to import that node_modules css file into another css file, and then importing that globally as well like so:
Which browser are you using? (if relevant)
Chrome, FireFox, Safari
How are you deploying your application? (if relevant)
next start
The text was updated successfully, but these errors were encountered: