forked from discretize/discretize-gear-optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
40 lines (36 loc) · 1.32 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
/* eslint-disable import/prefer-default-export */
/* eslint-disable react/jsx-filename-extension */
import React from 'react';
import { Provider } from 'react-redux';
import { renderToString } from 'react-dom/server';
import { JssProvider } from 'react-jss';
import { PersistGate } from 'redux-persist/integration/react';
import { Spinner } from 'gw2-ui-bulk';
import getPageContext from './src/utils/getPageContext';
import createStore from './src/state/createStore';
export const replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => {
const { store, persistor } = createStore();
const { sheetsRegistry } = getPageContext();
replaceBodyHTMLString(
renderToString(
<Provider store={store}>
{/* TODO fix redux-persist breaking template swapping <PersistGate loading={<Spinner />} persistor={persistor}> */}
<PersistGate loading={<Spinner />} persistor={persistor}>
<JssProvider registry={sheetsRegistry}>{bodyComponent}</JssProvider>
</PersistGate>
{/* </PersistGate> */}
</Provider>,
),
);
setHeadComponents([
<style
type="text/css"
id="jss-server-side"
key="jss-server-side"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: sheetsRegistry.toString(),
}}
/>,
]);
};