1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

examples/with-react-helmet: upgrade react-helmet to v5.1.3 and fix invariant violation caused by bodyAttributes (#2587)

This commit is contained in:
Micooz Lee 2017-07-18 14:03:21 +08:00 committed by Tim Neutkens
parent d831e6d39c
commit 24a67ee967
2 changed files with 9 additions and 4 deletions

View file

@ -11,6 +11,6 @@
"next": "latest",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-helmet": "^4.0.0"
"react-helmet": "^5.1.3"
}
}

View file

@ -6,7 +6,7 @@ export default class extends Document {
const documentProps = await super.getInitialProps(...args)
// see https://github.com/nfl/react-helmet#server-usage for more information
// 'head' was occupied by 'renderPage().head', we cannot use it
return { ...documentProps, helmet: Helmet.rewind() }
return { ...documentProps, helmet: Helmet.renderStatic() }
}
// should render on <html>
@ -14,10 +14,15 @@ export default class extends Document {
return this.props.helmet.htmlAttributes.toComponent()
}
// should render on <body>
get helmetBodyAttrComponents () {
return this.props.helmet.bodyAttributes.toComponent()
}
// should render on <head>
get helmetHeadComponents () {
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())
}
@ -37,7 +42,7 @@ export default class extends Document {
{ this.helmetJsx }
{ this.helmetHeadComponents }
</Head>
<body>
<body {...this.helmetBodyAttrComponents}>
<Main />
<NextScript />
</body>