[docs] Gatsby order conflict in SSR output (head/JSS vs. body/emotion)
See original GitHub issueI’m following this example exactly: https://github.com/mui-org/material-ui/tree/next/examples/gatsby
Here’s my gatsby-config.js (abbreviated):
module.exports = {
plugins: [
"gatsby-plugin-layout",
{
resolve: "gatsby-plugin-material-ui",
options: {},
},
"gatsby-plugin-emotion",
],
};
Gatsby-browser.js:
export { wrapPageElement, wrapRootElement } from "./sharedGatsby";
Gatsby-ssr.js
export { wrapPageElement, wrapRootElement } from "./sharedGatsby";
SharedGatsby.js
import React from "react";
import theme from "./src/theme";
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
export const wrapRootElement = ({ element }) => {
return (
<ThemeProvider theme={createMuiTheme(theme)}>
{element}
</ThemeProvider>
);
};
In pages/index.js:
import {
Typography,
makeStyles,
} from "@material-ui/core";
const useStyles = makeStyles({
typographyHeader: {
fontWeight: "bold",
fontSize: ({ isOnMobile }) => (isOnMobile ? 30 : 30),
color: textColor,
},
});
<StyledEngineProvider injectFirst>
<Typography classes={{ root: classes.typographyHeader }} align="center">
Goodbye, Excel.
<Box>Hello, automated Discounted Cash Flows.</Box>
</Typography>
...other components
</StyledEngineProvider>
package.json:
"@material-ui/core": "^5.0.0-alpha.25",
"@material-ui/icons": "^5.0.0-alpha.24",
"@material-ui/styles": "^5.0.0-alpha.25",
"@emotion/react": "^11.1.1",
"@emotion/styled": "^11.0.0",
"gatsby": "^2.32.3",
"gatsby-plugin-material-ui": "^2.1.10",
"gatsby-plugin-emotion": "^6.0.0",
It works 100% fine on the client side but when I run npm run build
and generate a static SSR index.html the styles order is incorrect.
Here’s the output:
You can see that my custom styles .jss4 and .jss2 are being overwritten by MuiTypography-root.
I imagine I’m doing something wrong but not sure what.
Thanks for any help
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
[docs] Gatsby order conflict in SSR output (head/JSS vs. body ...
Use styled-components instead of emotion. styled-components doesn't render it's style inside the body, with the order of the Gatsby plugins, you ...
Read more >Server Side Rendering - Emotion
This returns an object with the properties html , ids and css . It pulls out Emotion rules that are actually used in...
Read more >Server-Side Rendering API - Gatsby
Server-Side Rendering (SSR) allows you to render a page at run-time with data that is fetched when a ... headers: {}, // HTTP...
Read more >Gatsby Changelog | 5.3.0
Now, when a code update or data update is made for the <Header> component, only the HTML for the Slice will be updated,...
Read more >Material UI v5 server side rendering css order not working with ...
@MartinDawson I had a look at your issue. I believe this problem can't be solved with the current API exposed by Gatsby and...
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 FreeTop 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
Top GitHub Comments
It’s a shame it’s not working anymore, Gatsby is incredibly popular, including the Mui plugins Gatsby has
@mojimi What makes you think that it’s “not working anymore”. It’s popular, but not really growing.
@MartinDawson I had a look at your issue. I believe this problem can’t be solved with the current API exposed by Gatsby and emotion. What we would need is the capability to extract the CSS output from the HTML page, and inline it in the initial SSR request, before the JSS output.
You have 3 options:
While looking at the issue. I noticed this simplification opportunity:
In case somebody want to work on it 👍