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.

Built-in CSS Module Support Not Injecting *.module.css styling during SSR

See original GitHub issue

Bug report

Describe the bug

The new built-in css module support does not work during SSR, at least not without further configuration that I’m not aware of. Once the page is loaded client side, the styles are injected for the component and everything looks as it should.

I checked the html using Postman http client and noticed that there’s no <style></style> element injected in the <head /> element. However, after the page loads in a browser, that <style></style> element is injected with the expected scoped css.

I tried the basic example from the blog post, and it worked. However, there’s no example with SSR and components.

To Reproduce

I have a custom pages/_app.jsx and a component somewhere in my pages/index.jsx page, which is server side rendered using getInitialProps(). The component imports its own ./comp.module.css file.

Expected behavior

The css modules imported across my app structure should be gathered during server side rendering and injected into the <head/> of my html that is sent to the client. That way, when the user first sees my page, all the styling is in place.

Screenshots

What’s sent down from SSR:

Screen Shot 2020-01-25 at 8 51 12 PM

What’s show after the module’s css is finally injected into the <head/> on the client:

Screen Shot 2020-01-25 at 8 51 13 PM

System information

OS: macOS Browser: Chrome Version of Next.js: 9.2.1

Additional context

This may be related to https://github.com/zeit/next.js/issues/10267 This is the feature I’m referring to: https://nextjs.org/blog/next-9-2#built-in-css-module-support-for-component-level-styles

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
joonhochocommented, Jan 26, 2020

having the same issue as well for both development and production mode.

1reaction
Timercommented, Jun 22, 2020

No, JavaScript cannot be disabled in development.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Built-in CSS Support - Next.js
CSS Modules locally scope CSS by automatically creating a unique class name. This allows you to use the same CSS class name in...
Read more >
A Guide to CSS Modules with React - Code of Joy
To use CSS Modules in React components requires us to 'import' the CSS source file we want to use: import React from 'react';...
Read more >
Server Side Rendering with CSS Modules | by Mathias Vagni
It's currently still relatively hard to understand how to use CSS modules on the server & client based on existing docs.
Read more >
How to SSR CSS modules? - webpack - Stack Overflow
I'm using NextJS with CSS modules. ... To do so, I need to extract the CSS used within the components and ... Are...
Read more >
css-loader | webpack - JS.ORG
If set to false , css-loader will not parse any paths specified in url or ... To import styles from a node_modules path...
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