Skip to content

Commit

Permalink
fix(document): accepts nodearray for head's children
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Mar 18, 2022
1 parent bc46022 commit 16c1975
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/next/pages/_document.tsx
Expand Up @@ -19,7 +19,7 @@ export { DocumentContext, DocumentInitialProps, DocumentProps }
export type OriginProps = {
nonce?: string
crossOrigin?: string
children?: React.ReactElement
children?: React.ReactNode
}

type DocumentFiles = {
Expand Down Expand Up @@ -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

Expand All @@ -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
)
Expand Down

0 comments on commit 16c1975

Please sign in to comment.