-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Next.js removes css modules causing unstyled pages in production #68328
Comments
A reproduction repo on Stackblitz, https://stackblitz.com/edit/nextjs-6mb95w?file=pages%2Fabout.tsx,pages%2Findex.tsx,components%2Flazy.tsx, just cancel the command, and run, Removed a bunch of code not needed to reproduce the issue, and included |
So, the issue seems to, at least, be originating here, next.js/packages/next/src/client/index.tsx Lines 682 to 697 in cab4b65
Specifically here: styleTag.setAttribute('media', 'x') Changing to |
@jantimon Thank you for submitting an issue! Is there a reason why you are not using |
The Stackblitz example I made does use next/dynamic though. Same problem. |
@icyJoseph @jantimon It looks like this is related to this long-running issue → #33286. Good news, we've actually started picking this up! → #68396 |
@samcx - Good news really really cool! @samcx - why no
@icyJoseph - There are two different systems running: the extract text plugin which adds code to lazy loads the css chunk and the nextjs router which adds/removes styles to keep the correct order and tries to apply only relevant styles for the current page - the problem seems to be that the mini-css-extract-plugin adds the lazy css only once but nextjs will remove it every time you go to another page |
## Why? To help flag severe issues, we can use utilize AI to digest the `context.payload.issue` object each time an issue is opened and determine whether that issue is severe enough to flag to the Next.js team on Slack. ## How? Making a Tool Call using using the :ai-stonks: SDK. The :ai-stonks: will call the Tool and report to Slack (to the `#next-info` channel`) if it determines that the issue is severe enough, using the context of the issue, latest Next.js versions, and a Triage Guideline. ## Testing This was tested on a separate test repo with issues #68328 (real issue) and #68336 (blank test issue). ![CleanShot 2024-07-30 at 12 07 43@2x](https://github.com/user-attachments/assets/7a35514e-840d-41db-b1a7-6021fe389458) ![CleanShot 2024-07-30 at 12 10 26@2x](https://github.com/user-attachments/assets/c7e17612-59b6-4ce3-8b7f-ea96c3e09680)
I am getting the same issue now with app router, some css modules simply not loading for certain routes. Happens on both dev and prod |
@max-degterev that is probably another bug - can you please create a dedicated issue? |
Aha I've managed to trace the error. There is a rogue class with a semicolon after the closing curly. Because nextjs doesn't guarantee class order any class that follows that rogue definition will not apply. This is a floating bug that will be very hard to trace. Ideally compiler should throw or strip these. This little semicolon just cost me 4 hours. I'm not gonna create a separate issue for this because frankly your issue creation rules are not very inviting to collaborate. I will patch this in my codebase, the rest is up to you guys. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/gracious-keller-qdj5ld?file=%2Fpages%2Findex.tsx%3A1%2C29
To Reproduce
Reproduction steps using the provided CodeSandbox:
Video:
CSSModules.mp4
Current vs. Expected behavior
Current behavior:
When navigating from a page with both normally loaded and lazy-loaded components to a page with only lazy-loaded components, the CSS for the lazy-loaded component is missing.
Expected behavior:
The CSS for lazy-loaded components should be properly applied regardless of the navigation path or the loading method on the previous page.
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Available memory (MB): 4102 Available CPU cores: 2 Binaries: Node: 20.9.0 npm: 9.8.1 Yarn: 1.22.19 pnpm: 8.10.2 Relevant Packages: next: 15.0.0-canary.91 // Latest available version is detected (15.0.0-canary.91). eslint-config-next: N/A react: 19.0.0-rc.0 react-dom: 19.0.0-rc.0 typescript: 5.3.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Lazy Loading, Pages Router
Which stage(s) are affected? (Select all that apply)
next build (local), Vercel (Deployed)
Additional context
next
12.3.4next
13.0.0next
14.0.0next
14.1.3next
14.2.3next
15.0.0-canary.91pages
router - theapp
router seems to work finenpm run build
-npm run dev
seems to work finepackages/next/src/client/index.tsx
The text was updated successfully, but these errors were encountered: