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.

[Bug] CSS Module + ReactRouter: ClassNames aren't added to the generated HTML

See original GitHub issue

The 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

https://github.com/rickyrombo/react-static-css-modules-bug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Shipleavescommented, May 2, 2019

This affects me too, would be great to see this fixed.

1reaction
DominikGuzeicommented, Jan 1, 2020

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:

// Node
// Don't extract css to file during node build process
loaders = [{
  ...cssLoader,
  options: {
    ...cssLoader.options,
    exportOnlyLocals: true,
  },
}, sassLoader]
Read more comments on GitHub >

github_iconTop 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 >

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