From 16c19755679bc6a1f2b71340d03c605c6e82eff3 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Thu, 17 Mar 2022 23:59:33 -0700 Subject: [PATCH] fix(document): accepts nodearray for head's children --- packages/next/pages/_document.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 8ac37914b0026..555f225e3ff93 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -19,7 +19,7 @@ export { DocumentContext, DocumentInitialProps, DocumentProps } export type OriginProps = { nonce?: string crossOrigin?: string - children?: React.ReactElement + children?: React.ReactNode } type DocumentFiles = { @@ -72,6 +72,10 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) { )) } +function hasComponentProps(child: any): child is React.ReactElement { + return !!child && !!child.props +} + function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) { const { assetPrefix, scriptLoader, crossOrigin, nextScriptWorkers } = context @@ -88,7 +92,8 @@ function getPreNextWorkerScripts(context: HtmlProps, props: OriginProps) { // Check to see if the user has defined their own Partytown configuration const userDefinedConfig = children.find( - (child: React.ReactElement) => + (child) => + hasComponentProps(child) && child?.props?.dangerouslySetInnerHTML?.__html.length && 'data-partytown-config' in child.props )