Commit 267cff3b authored by HaNdTriX's avatar HaNdTriX Committed by Tim Neutkens

Remove dublicate className from head (#5026)

This PR:

* Removes dublicate `className` in: `<meta charSet="utf-8" class="next-head"/>`
* Refactores head reducer

Special thanks to @udanpe for reporting and @geoffRGWilliams for bringing me on the right tack! 🙌

Closes #4745, #4802 
parent 1babde10
......@@ -12,14 +12,15 @@ class Head extends React.Component {
}
}
export function defaultHead () {
return [<meta charSet='utf-8' className='next-head' />]
const NEXT_HEAD_IDENTIFIER = 'next-head'
export function defaultHead (className = NEXT_HEAD_IDENTIFIER) {
return [<meta charSet='utf-8' className={className} />]
}
function reduceComponents (components) {
return components
.map((c) => c.props.children)
.map((children) => React.Children.toArray(children))
.map((component) => React.Children.toArray(component.props.children))
.reduce((a, b) => a.concat(b), [])
.reduce((a, b) => {
if (React.Fragment && b.type === React.Fragment) {
......@@ -28,12 +29,12 @@ function reduceComponents (components) {
return a.concat(b)
}, [])
.reverse()
.concat(...defaultHead())
.filter((c) => !!c)
.concat(defaultHead())
.filter(Boolean)
.filter(unique())
.reverse()
.map((c) => {
const className = (c.props && c.props.className ? c.props.className + ' ' : '') + 'next-head'
const className = (c.props && c.props.className ? c.props.className + ' ' : '') + NEXT_HEAD_IDENTIFIER
return React.cloneElement(c, { className })
})
}
......
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