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
Built-in CSS Module Support Not Injecting *.module.css styling during SSR #10268
Comments
I see that the CSS modules page mentions having to also use the postcss plugin to use css modules on the server side. Is postcss the suggested solution to my issue? I'd greatly appreciate an example of this new feature with a basic SSR app to see how I'm supposed to hook this up. https://github.com/css-modules/css-modules#server-side-and-static-websites |
This comment has been minimized.
This comment has been minimized.
having the same issue as well for both development and production mode. |
This comment has been minimized.
This comment has been minimized.
Can you provide a complete reproducible demo so that we can have a look |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@Lwdthe1 can you please provide a reproducible demo? 🙏 |
Hey, I'm sorry for the delay, but my table is currently a bit full with interview projects, so I don't have time today to make the repro. I can shoot for tomorrow. |
@Lwdthe1 any update? |
Created issue #10404 for a very similar issue. Repro is https://github.com/ramasilveyra/bug-repro-next-global-css. |
I'm also noticing a problem with the injecting * .module.css to SSR header. @timneutkens @Timer Reproduction is simple. Clone with-next-css example. Execute. Disable JS in the browser and refresh the page. In my opinion, it would be appropriate to include CSS modules to the SSR page header, because SSR is very often used to improve user experience and speed up loading. Unfortunately, a site without styles looks tragic. |
My apologies for never following up on this. I never figured it out and have moved away from it since. |
Closing since OP no longer has the issue. |
This should be fixed in |
Thanks @Timer, it seems to work! Is JavaScript disabled also supported? When I disable JS I don't see my custom styles but it could be that my setup is wrong or outdated. |
No, JavaScript cannot be disabled in development. |
@Timer Hey
Hey, what has been fixed in this version specifically (CSS module can be SSR-ed from 9.4.5)? I am actually having a similar requirement: I have a standalone navbar and footer, in order to make them work in basically any React app I implemented them So is using style-loader in webpack in next.config.js a workaround? Any thoughts, thanks |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
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 mypages/index.jsx
page, which is server side rendered usinggetInitialProps()
. 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:
What's show after the module's css is finally injected into the
<head/>
on the client:System information
OS: macOS
Browser: Chrome
Version of Next.js: 9.2.1
Additional context
This may be related to #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
The text was updated successfully, but these errors were encountered: