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:
parent
1babde1026
commit
267cff3b81
15
lib/head.js
15
lib/head.js
|
@ -12,14 +12,15 @@ class Head extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defaultHead () {
|
const NEXT_HEAD_IDENTIFIER = 'next-head'
|
||||||
return [<meta charSet='utf-8' className='next-head' />]
|
|
||||||
|
export function defaultHead (className = NEXT_HEAD_IDENTIFIER) {
|
||||||
|
return [<meta charSet='utf-8' className={className} />]
|
||||||
}
|
}
|
||||||
|
|
||||||
function reduceComponents (components) {
|
function reduceComponents (components) {
|
||||||
return components
|
return components
|
||||||
.map((c) => c.props.children)
|
.map((component) => React.Children.toArray(component.props.children))
|
||||||
.map((children) => React.Children.toArray(children))
|
|
||||||
.reduce((a, b) => a.concat(b), [])
|
.reduce((a, b) => a.concat(b), [])
|
||||||
.reduce((a, b) => {
|
.reduce((a, b) => {
|
||||||
if (React.Fragment && b.type === React.Fragment) {
|
if (React.Fragment && b.type === React.Fragment) {
|
||||||
|
@ -28,12 +29,12 @@ function reduceComponents (components) {
|
||||||
return a.concat(b)
|
return a.concat(b)
|
||||||
}, [])
|
}, [])
|
||||||
.reverse()
|
.reverse()
|
||||||
.concat(...defaultHead())
|
.concat(defaultHead())
|
||||||
.filter((c) => !!c)
|
.filter(Boolean)
|
||||||
.filter(unique())
|
.filter(unique())
|
||||||
.reverse()
|
.reverse()
|
||||||
.map((c) => {
|
.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 })
|
return React.cloneElement(c, { className })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue