[Bug] CSS Module + ReactRouter: ClassNames aren't added to the generated HTML
See original GitHub issueThe inital load of any of my pages lacks the proper classes, thus the stylling is all wrong on initial load.
Environment
System:
OS: Windows 10
CPU: (8) x64 AMD FX(tm)-8350 Eight-Core Processor
Memory: 16.56 GB / 31.98 GB
Binaries:
Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 5.3.0 - C:\Users\me\AppData\Roaming\npm\npm.CMD
Browsers:
Edge: 44.17763.1.0
Internet Explorer: 11.0.17763.1
npmPackages:
react: ^16.8.2 => 16.8.6
react-dom: ^16.8.2 => 16.8.6
react-router-dom: ^5.0.0 => 5.0.0
react-static: ^7.0.0 => 7.0.10
react-static-plugin-css-modules: ^7.0.8 => 7.0.8
react-static-plugin-react-router: ^7.0.8 => 7.0.8
react-static-plugin-sitemap: ^7.0.0 => 7.0.0
react-static-plugin-source-filesystem: ^7.0.0 => 7.0.0
react-transition-group: ^4.0.0 => 4.0.0
Expected Behavior
yarn start
and yarn build
yield same result.
Initial load has classNames/styles as appropriate.
Note that navigation using <Link />
components causes rerendering of that particular element, thus causing the classNames to get applied.
Reproducible Demo
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
CSS Module class names change, but aren't updated in markup
The generated class names in the compiled CSS update as the file is changed, but the classes are not updated in markup. Possible...
Read more >react-css-modules is not working correctly - Stack Overflow
So, the css file should named: Component.module.css . Finally, you can use it like this: import React from "react"; import styles from "....
Read more >Solving the React Error: Not Picking Up CSS Style | Pluralsight
This error is generated because the compiler is only able to import files from the src folder. Here, the CSS file is saved...
Read more >Frequently Asked Questions - Material UI - MUI
The CSS alternative provides more advantages, such as: auto-prefixing; better debugging; media queries; keyframes. How do I use react-router?
Read more >Migrating your React Router App to Remix
Creating server and browser entrypoints. Most React Router apps run primarily in the browser. The server's only job is to send a single...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This affects me too, would be great to see this fixed.
I just ran into this issue with the latest
react-static@7.2.3
version. The stylesheet gets generated correctly but the built, static DOM does not have the classes assigned - so the styles are not applied with Javascript turned off - this only happens after the react app was mounted. @benedfit can you tell me how you solved the issue?EDIT: nevermind, i solved the issue by copying the setup of the css-modules plugin into my custom sass plugin …
exportOnlyLocals: true
was the important part: