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

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
This commit is contained in:
HaNdTriX 2018-08-25 00:19:54 +02:00 committed by Tim Neutkens
parent 1babde1026
commit 267cff3b81

View file

@ -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 })
})
}