From b065dafa529cb06dd733887fa6e7dc88a2e71b03 Mon Sep 17 00:00:00 2001 From: Henrik Wenz Date: Sat, 29 Sep 2018 06:52:36 +0200 Subject: [PATCH] Refactor head keys (#5326) We don't need to `React.cloneElement`, twice. --- lib/head.js | 9 ++++++--- server/document.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/head.js b/lib/head.js index 5454df8f9bc39..4e0b257040c97 100644 --- a/lib/head.js +++ b/lib/head.js @@ -15,7 +15,9 @@ class Head extends React.Component { const NEXT_HEAD_IDENTIFIER = 'next-head' export function defaultHead (className = NEXT_HEAD_IDENTIFIER) { - return [] + return [ + + ] } function reduceComponents (components) { @@ -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 }) }) } diff --git a/server/document.js b/server/document.js index d3c418171ab85..cfb38f368d2f6 100644 --- a/server/document.js +++ b/server/document.js @@ -116,7 +116,7 @@ export class Head extends Component { } return - {(head || []).map((h, i) => React.cloneElement(h, { key: h.key || i }))} + {head} {page !== '/_error' && }