Commit 24a67ee9 authored by Micooz Lee's avatar Micooz Lee Committed by Tim Neutkens

examples/with-react-helmet: upgrade react-helmet to v5.1.3 and fix invariant…

examples/with-react-helmet: upgrade react-helmet to v5.1.3 and fix invariant violation caused by bodyAttributes (#2587)
parent d831e6d3
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
"next": "latest", "next": "latest",
"react": "^15.4.2", "react": "^15.4.2",
"react-dom": "^15.4.2", "react-dom": "^15.4.2",
"react-helmet": "^4.0.0" "react-helmet": "^5.1.3"
} }
} }
...@@ -6,7 +6,7 @@ export default class extends Document { ...@@ -6,7 +6,7 @@ export default class extends Document {
const documentProps = await super.getInitialProps(...args) const documentProps = await super.getInitialProps(...args)
// see https://github.com/nfl/react-helmet#server-usage for more information // see https://github.com/nfl/react-helmet#server-usage for more information
// 'head' was occupied by 'renderPage().head', we cannot use it // 'head' was occupied by 'renderPage().head', we cannot use it
return { ...documentProps, helmet: Helmet.rewind() } return { ...documentProps, helmet: Helmet.renderStatic() }
} }
// should render on <html> // should render on <html>
...@@ -14,10 +14,15 @@ export default class extends Document { ...@@ -14,10 +14,15 @@ export default class extends Document {
return this.props.helmet.htmlAttributes.toComponent() return this.props.helmet.htmlAttributes.toComponent()
} }
// should render on <body>
get helmetBodyAttrComponents () {
return this.props.helmet.bodyAttributes.toComponent()
}
// should render on <head> // should render on <head>
get helmetHeadComponents () { get helmetHeadComponents () {
return Object.keys(this.props.helmet) return Object.keys(this.props.helmet)
.filter(el => el !== 'htmlAttributes') // remove htmlAttributes which is not for <head> but for <html> .filter(el => el !== 'htmlAttributes' && el !== 'bodyAttributes')
.map(el => this.props.helmet[el].toComponent()) .map(el => this.props.helmet[el].toComponent())
} }
...@@ -37,7 +42,7 @@ export default class extends Document { ...@@ -37,7 +42,7 @@ export default class extends Document {
{ this.helmetJsx } { this.helmetJsx }
{ this.helmetHeadComponents } { this.helmetHeadComponents }
</Head> </Head>
<body> <body {...this.helmetBodyAttrComponents}>
<Main /> <Main />
<NextScript /> <NextScript />
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment