ํน์ ์คํ์ผ ์กฐํฉ์ ์ฌ์ฉํ๋ฉด ๋ ๋๋ง๋ ํ์ด์ง ๊ฐ์ SheetsRegistry๋ฅผ ์ง์์ผ ํฉ๋๋ค.
์ด ๋ฆฌํฌ์งํ ๋ฆฌ์๋ ๋จ์ํ๋ ์ฌ์์ฐ์ด ์์ผ๋ฉฐ ์ด์ ๋ํ ์์ ์ฌํญ์ ์ถ์ ํฉ๋๋ค.
https://github.com/cpboyd/gatsby-layout-mui-bug
์ฐธ๊ณ : SheetsRegistry
์ฌ์ค์ ํด์ผ ํ๋ ์์น๊ฐ ํ์คํ์ง ์์ต๋๋ค. ์ ๋ ToString()
ํธ์ถ ํ์ ๋ฐฐ์นํ๊ธฐ ๊ฐ์ฅ ์ฌ์ด ์์น์ ๋ฐฐ์นํ์ต๋๋ค.
ํ์ด์ง๋ ์๋ฐ์คํฌ๋ฆฝํธ ๋ ๋๋ง๊ณผ ์ ์ ๋ ๋๋ง ๊ฐ์ ์ผ๊ด๋๊ฒ ๋ ๋๋ง๋์ด์ผ ํฉ๋๋ค.
์คํ์ผ์ด ๋ค์ฃฝ๋ฐ์ฃฝ์ด์๋ค.
์ฒด๊ณ:
OS: macOS ํ์ด ์์๋ผ 10.13.6
CPU: x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
์
ธ: 3.2.57 - /bin/bash
๋ฐ์ด๋๋ฆฌ:
๋
ธ๋: 10.9.0 - /usr/local/bin/node
์์ฌ: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.0 - /usr/local/bin/npm
๋ธ๋ผ์ฐ์ :
ํฌ๋กฌ: 68.0.3440.106
์ฌํ๋ฆฌ: 11.1.2
npmํจํค์ง:
๊ฐ์ธ ๋น: ^2.0.0-rc.0 => 2.0.0-rc.0
๊ฐ์ธ ๋น ์ด๋ฏธ์ง: ^2.0.0-rc.0 => 2.0.0-rc.0
gatsby-plugin-google-analytics: ^2.0.0-rc.0 => 2.0.0-rc.0
gatsby-plugin-jss: ^2.0.2-rc.0 => 2.0.2-rc.0
๊ฐ์ธ ๋น ํ๋ฌ๊ทธ์ธ ๋ ์ด์์: ๋ค์ => 1.0.0-rc.0
๊ฐ์ธ ๋น ํ๋ฌ๊ทธ์ธ ๋งค๋ํ์คํธ: ^2.0.2-rc.0 => 2.0.2-rc.0
gatsby ํ๋ฌ๊ทธ์ธ ์คํ๋ผ์ธ: ^2.0.0-rc.0 => 2.0.0-rc.0
gatsby-plugin-react-helmet: ^3.0.0-rc.0 => 3.0.0-rc.0
gatsby-plugin-sharp: ^2.0.0-rc.0 => 2.0.0-rc.0
gatsby-plugin-typescript: ^2.0.0-rc.0 => 2.0.0-rc.1
gatsby-plugin-typography: ^2.2.0-rc.0 => 2.2.0-rc.0
gatsby-remark-external-links: ^0.0.4 => 0.0.4
gatsby-remark-images: ^2.0.1-rc.0 => 2.0.1-rc.0
gatsby-remark-responsive-iframe: ^2.0.0-rc.0 => 2.0.0-rc.0
๊ฐ์ธ ๋น ์์ค ํ์ผ ์์คํ
: ^2.0.1-rc.0 => 2.0.1-rc.0
gatsby-transformer-json: ^2.1.1-rc.0 => 2.1.1-rc.0
gatsby-transformer-remark: ^2.1.1-rc.0 => 2.1.1-rc.0
๊ฐ์ธ ๋น ํธ๋์คํฌ๋จธ ์คํ: ^2.1.1-rc.0 => 2.1.1-rc.0
npmGlobalํจํค์ง:
๊ฐ์ธ ๋น-cli: 1.1.58
gatsby-config.js
: ํด๋น ์ฌํญ ์์
package.json
: ํด๋น ์ฌํญ ์์
gatsby-node.js
: ํด๋น ์ฌํญ ์์
gatsby-browser.js
: ํด๋น ์ฌํญ ์์
์๋ gatsby-ssr.js
API๋ ํ์ด์ง๋ฅผ ๋ ๋๋งํ ๋๋ง๋ค ์๋ก์ด SheetsRegistry
์์ํ์ต๋๋ค.
exports.replaceRenderer = (
{ bodyComponent, replaceBodyHTMLString, setHeadComponents },
{ theme = {} }
) => {
const sheets = new SheetsRegistry()
const bodyHTML = renderToString(
<JssProvider registry={sheets}>
<ThemeProvider theme={theme}>{bodyComponent}</ThemeProvider>
</JssProvider>
)
replaceBodyHTMLString(bodyHTML)
setHeadComponents([
<style
type="text/css"
id="server-side-jss"
key="server-side-jss"
dangerouslySetInnerHTML={{ __html: sheets.toString() }}
/>,
])
}
์ด์ ๋ณ์๋ ํ์ผ ๋ฒ์์ด๋ฉฐ ๋ ๋๋ง ์ ๋ฐ์ ๊ฑธ์ณ ์ง์๋๋ ๊ฒ ๊ฐ์ต๋๋ค.
import React from "react"
import { JssProvider, SheetsRegistry, ThemeProvider } from "react-jss"
const sheets = new SheetsRegistry()
// eslint-disable-next-line react/prop-types,react/display-name
exports.wrapRootElement = ({ element }, { theme = {} }) => (
<JssProvider registry={sheets}>
<ThemeProvider theme={theme}>{element}</ThemeProvider>
</JssProvider>
)
exports.onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<style
type="text/css"
id="server-side-jss"
key="server-side-jss"
dangerouslySetInnerHTML={{ __html: sheets.toString() }}
/>,
])
๋น์ ์ด ๋ง์ต๋๋ค. setHeadComponents
๋ฅผ wrapRootElement
ํด์ผ SheetsRegistry
๊ฐ ํด๋น ํจ์ ๋ฒ์ ์์ ๋ค์ด๊ฐ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ฌ์ (
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋น์ ์ด ๋ง์ต๋๋ค.) ๋จ์ผ ๊ธ๋ก๋ฒ ๋ ์ง์คํธ๋ฆฌ ๋์ .
setHeadComponents
๋ฅผwrapRootElement
ํด์ผSheetsRegistry
๊ฐ ํด๋น ํจ์ ๋ฒ์ ์์ ๋ค์ด๊ฐ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ฌ์ (