Skip to content

Commit

Permalink
examples/with-react-helmet: upgrade react-helmet to v5.1.3 and fix in…
Browse files Browse the repository at this point in the history
…variant violation caused by bodyAttributes (vercel#2587)
  • Loading branch information
micooz authored and timneutkens committed Jul 18, 2017
1 parent d831e6d commit 24a67ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/with-react-helmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
11 changes: 8 additions & 3 deletions examples/with-react-helmet/pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 6,23 @@ 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>
get helmetHtmlAttrComponents () {
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())
}

Expand All @@ -37,7 42,7 @@ export default class extends Document {
{ this.helmetJsx }
{ this.helmetHeadComponents }
</Head>
<body>
<body {...this.helmetBodyAttrComponents}>
<Main />
<NextScript />
</body>
Expand Down

0 comments on commit 24a67ee

Please sign in to comment.