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.

react-static-plugin-jss configured for MaterialUI doesn't always insert correct CSS

See original GitHub issue

When using react-static-plugin-jss configured to use MaterialUI as shown in the guide, some routes are rendered with the correct CSS, but others are not. In the cases where it is missing, the <style id="jss-server-side"> tag with some minimal CSS is still inserted, but it is not the correct CSS that should be getting rendered.

Environment

  1. react-static -V: 6.1.4
  2. node -v: 11.4.0
  3. npm -v: 6.4.1
  4. Operating system: Windows 10 x64
  5. Browser and version (if relevant): N/A

Reproducible Demo

Here is the branch in my repository with the plugin setup: https://github.com/Herohtar/thalion-herohtar/tree/jss-plugin

After running build the root index.html does not contain the correct MaterialUI CSS, but 404.html does. Looking into the routes, blog/2018/index.html does not contain the correct CSS, but blog/2017/index.html does. There are some other pages that are missing the MaterialUI CSS as well.

For comparison, here is the main branch that is just using a dropped-in node.api.js configured for MaterialUI and the CSS is rendered correctly on all pages: https://github.com/Herohtar/thalion-herohtar/tree/master

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
tannerlinsleycommented, Jan 5, 2019

I’ll take a closer look as soon as I can

On Sat, Jan 5, 2019 at 2:33 PM Herohtar notifications@github.com wrote:

So looking at it some more, the docs seem to imply that you have to give it a MuiThemeProvider to use SSR at all for MaterialUI, and state that you need to create a new instance of the sheets manager, sheets registry, and class name generator for each request. I’m not sure of the exact details of how those work together, but it seems separating them out like that causes them to not function correctly.

Even without trying to insert MuiThemeProvider somewhere, there is still the inconsistent CSS when trying to use MaterialUI with the jss plugin as currently described by the guide. I think it is more than just an edge case and will require it’s own plugin… I’m not sure how you could write it to use the jss plugin since MuiThemeProvider needs to be inserted below JssProvider…

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/nozzle/react-static/issues/940#issuecomment-451692147, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCXNiLThXkqky41cnFDJnbofArQPcks5vARo7gaJpZM4ZpOHG .

1reaction
Herohtarcommented, Jan 5, 2019

So looking at it some more, the docs seem to imply that you have to give it a MuiThemeProvider to use SSR at all for MaterialUI, and state that you need to create a new instance of the sheets manager, sheets registry, and class name generator for each request. I’m not sure of the exact details of how those work together, but it seems separating them out like that causes them to not function correctly.

Even without trying to insert MuiThemeProvider somewhere, there is still the inconsistent CSS when trying to use MaterialUI with the jss plugin as currently described by the guide. I think it is more than just an edge case and will require it’s own plugin… I’m not sure how you could write it to use the jss plugin since MuiThemeProvider needs to be inserted below JssProvider

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to customize - Material UI - MUI
Learn how to customize Material UI components by taking advantage of different strategies for specific use cases.
Read more >
Troubleshooting - Material UI - MUI
First, check if you have configured the StyledEngineProvider correctly, as shown in the Style library section. If the StyledEngineProvider is already used ...
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 >
Style library interoperability - Material UI - MUI
After the style engine is configured properly, you can use the styled() utility from @mui/material/styles and have direct access to the theme.
Read more >
Migrating to v5: getting started - Material UI - MUI
This guide explains how and why to migrate from Material UI v4 to v5. ... will automatically address many of the breaking changes...
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