question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS modules duplicated when used with `next/dynamic`

See original GitHub issue

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: https://github.com/vercel/next.js/issues/20203.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:20
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
rikanicommented, Mar 9, 2022

Next.js v12.1.0 still has problem.

3reactions
NikooDevcommented, Jun 8, 2022

12.1.6 still has problem : Capture d’écran 2022-06-09 à 00 04 51

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic import module and css-modules(React, Next.js)
I want to understand the work of css-modules + dynamic modules. I have a global Button component that is used throughout the application....
Read more >
Component-Scoped Styles with CSS Modules - Gatsby
What is a CSS Module? CSS Module example; Enabling user stylesheets with a stable class name. When to use CSS Modules; How to...
Read more >
css modules cannot be imported from within node_modules
I am using the built in CSS modules for my components in Nextjs. ... import React from 'react'; import dynamic from 'next/dynamic'; const...
Read more >
CSS Modules Compiler
This module has been created to support a real project using css-modules, postcss and webpack to produce a library of reusable components.
Read more >
Dynamic imports and preloading in Next.js, doing it the right way
js preloads every dynamically imported module made using the next/dynamic package that renders on the server. One common mistake that web ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found