Skip to content

Commit

Permalink
Refactor head keys (#5326)
Browse files Browse the repository at this point in the history
We don't need to `React.cloneElement`, twice.
  • Loading branch information
HaNdTriX authored and timneutkens committed Sep 29, 2018
1 parent df41997 commit b065daf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class Head extends React.Component {
const NEXT_HEAD_IDENTIFIER = 'next-head'

export function defaultHead (className = NEXT_HEAD_IDENTIFIER) {
return [<meta charSet='utf-8' className={className} />]
return [
<meta key='charSet' charSet='utf-8' className={className} />
]
}

function reduceComponents (components) {
Expand All @@ -33,9 +35,10 @@ function reduceComponents (components) {
.filter(Boolean)
.filter(unique())
.reverse()
.map((c) => {
.map((c, i) => {
const className = (c.props && c.props.className ? c.props.className + ' ' : '') + NEXT_HEAD_IDENTIFIER
return React.cloneElement(c, { className })
const key = c.key || i
return React.cloneElement(c, { key, className })
})
}

Expand Down
2 changes: 1 addition & 1 deletion server/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class Head extends Component {
}

return <head {...this.props}>
{(head || []).map((h, i) => React.cloneElement(h, { key: h.key || i }))}
{head}
{page !== '/_error' && <link rel='preload' href={`${assetPrefix}/_next/static/${buildId}/pages${pagePathname}`} as='script' nonce={this.props.nonce} />}
<link rel='preload' href={`${assetPrefix}/_next/static/${buildId}/pages/_app.js`} as='script' nonce={this.props.nonce} />
<link rel='preload' href={`${assetPrefix}/_next/static/${buildId}/pages/_error.js`} as='script' nonce={this.props.nonce} />
Expand Down

0 comments on commit b065daf

Please sign in to comment.