From 267cff3b81a90307dbb522552043aa6adfdff8bc Mon Sep 17 00:00:00 2001 From: HaNdTriX Date: Sat, 25 Aug 2018 00:19:54 +0200 Subject: [PATCH] Remove dublicate className from head (#5026) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR: * Removes dublicate `className` in: `` * Refactores head reducer Special thanks to @udanpe for reporting and @geoffRGWilliams for bringing me on the right tack! 🙌 Closes #4745, #4802 --- lib/head.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/head.js b/lib/head.js index d7b1423f..ef206c54 100644 --- a/lib/head.js +++ b/lib/head.js @@ -12,14 +12,15 @@ class Head extends React.Component { } } -export function defaultHead () { - return [] +const NEXT_HEAD_IDENTIFIER = 'next-head' + +export function defaultHead (className = NEXT_HEAD_IDENTIFIER) { + return [] } 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 }) }) }