-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgatsby-ssr.js
41 lines (34 loc) · 1.27 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
// You can delete this file if you're not using it
const React = require('react');
const { renderToString } = require('react-dom/server');
const JssProvider = require('react-jss/lib/JssProvider').default;
const getPageContext = require('./src/components/getPageContext').default;
function replaceRenderer({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) {
// Get the context of the page to collected side effects.
const muiPageContext = getPageContext();
const bodyHTML = renderToString(
<JssProvider registry={muiPageContext.sheetsRegistry}>{bodyComponent}</JssProvider>,
);
replaceBodyHTMLString(bodyHTML);
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
dangerouslySetInnerHTML={{ __html: muiPageContext.sheetsRegistry.toString() }}
/>,
]);
}
exports.replaceRenderer = replaceRenderer;
// It's not ready yet: https://github.com/gatsbyjs/gatsby/issues/8237.
//
// const withRoot = require('./src/withRoot').default;
// const WithRoot = withRoot(props => props.children);
// exports.wrapRootElement = ({ element }) => {
// return <WithRoot>{element}</WithRoot>;
// };