-
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
CSS modules duplicated when used with next/dynamic
#25456
Comments
I'm getting duplicate css without using dynamic. |
@sgehrman please provide a reproduction |
I am encountering a similar issue - CSS modules are getting duplicated and overwritten for similar components on a page - e.g. implementations of a custom Update: was initially on |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Next.js |
Next.js |
12.1.6 still has problem |
12.1.5 still has problem |
Repo to reproduce this: After adding dynamic component using the same "shared" component Since you need css chunks to reproduce it you have to do build+start
When second component get added its css brings the "shared" styles again affecting the cascade order: |
Yeah, 12.2.3 still no workaround |
Experienced this issue in 12.3.1 and found a workaround. TL;DR: add a hidden ( Explanation: webpack (or whatever) seems to check whether components used in a Say you have a few components:
* The issue may be reproduced in a few ways:
When building Next.js checks imports to see whether components used in My workaround was the following: add a hidden ( Perhaps it is also possible to not render the component at all by using |
It seems that this issue is connected with: #42082 |
The same issue without using I'm wondering why this problem persists for a few years and a lot of tickets was closed without any solution.
|
any solutions for this issue? |
I am also having this issue with My instinct is that it has to do with SSR and the bundling magic between layouts/pages... |
I have the same issue with next@13.4.17. Any workarounds so far? |
I can actively reproduce it without dynamic.
Even if you have not visited both pages, if you have a Link component ( or something else that preloads the other page ). The server will stream down two css files, both with the EXCACT same selectors. The browser for good reason can't dedup css selectors, instead it essentially does a merge. Ultimately I am just worried about the performance hit here, since it is doing the dedup on basically every shared component. Its also messy to read and a bad dev experience. Hope this helps :) |
This comment has been minimized.
This comment has been minimized.
This bug is present even without using next/dynamic |
I have the same issue in next@13.5.6 even without dynamic imports. Seriously this problem has been going on for so long and it still hasn't been fixed? |
…d of PageTitleWrapper. Also cancelled cache wrapping for getPropertyDevelopers to get fresh list each time user needs it. Also re-activated redirecting to the Home page when clicked on Sidebar logo. Related ongoing next.js bug of multiple css module files for the Sidebar(client component) rendered inside layout(server component) - @ref-link: vercel/next.js#25456
This is still an issue for me using next@14.1.3 EDIT: using dynamic imports |
It seems to be solved in |
is there any solution? In large projects where components are often reused, duplicating styles greatly increases the final css file size. |
We still see duplicate CSS for dynamic imports on 14.2.3 in our production builds. It would be great to have a fix for this! |
What version of Next.js are you using?
10.2.2
What version of Node.js are you using?
14.16.0
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
When using
next/dynamic
with CSS modules, we've found that CSS can be re-inserted (duplicated)In our scenario, we have a simple
<Text />
component that is already in use throughout the application. When we used<Text />
in a new component that was dynamically imported, styles for<Text />
were re-inserted.These styles were inserted below all other styles, breaking some styles that rely on specificity - which is how we found this bug.
As a temporary workaround, we've removed that component from the dynamically loaded component.
Expected Behavior
Styles should not be re-inserted/duplicated.
To Reproduce
We haven't been able to reliably reproduce this in a standalone repo.
We've looked and found some potentially similar issues, and this might be related: #20203.
The text was updated successfully, but these errors were encountered: