Unverified Commit eba9da09 authored by Oriol Collell's avatar Oriol Collell Committed by GitHub

Fixes #32338 missing Document components trigger an error for production builds (#32345)

* Only validate _document subcomponents in dev environment

* Replace error by a warning
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 10d814d3
...@@ -1375,25 +1375,27 @@ export async function renderToHTML( ...@@ -1375,25 +1375,27 @@ export async function renderToHTML(
documentHTML = ReactDOMServer.renderToStaticMarkup(document) documentHTML = ReactDOMServer.renderToStaticMarkup(document)
} }
const nonRenderedComponents = [] if (process.env.NODE_ENV !== 'production') {
const expectedDocComponents = ['Main', 'Head', 'NextScript', 'Html'] const nonRenderedComponents = []
const expectedDocComponents = ['Main', 'Head', 'NextScript', 'Html']
for (const comp of expectedDocComponents) { for (const comp of expectedDocComponents) {
if (!(docComponentsRendered as any)[comp]) { if (!(docComponentsRendered as any)[comp]) {
nonRenderedComponents.push(comp) nonRenderedComponents.push(comp)
}
} }
}
if (nonRenderedComponents.length) { if (nonRenderedComponents.length) {
const missingComponentList = nonRenderedComponents const missingComponentList = nonRenderedComponents
.map((e) => `<${e} />`) .map((e) => `<${e} />`)
.join(', ') .join(', ')
const plural = nonRenderedComponents.length !== 1 ? 's' : '' const plural = nonRenderedComponents.length !== 1 ? 's' : ''
throw new Error( console.warn(
`Your custom Document (pages/_document) did not render all the required subcomponent${plural}.\n` + `Your custom Document (pages/_document) did not render all the required subcomponent${plural}.\n` +
`Missing component${plural}: ${missingComponentList}\n` + `Missing component${plural}: ${missingComponentList}\n` +
'Read how to fix here: https://nextjs.org/docs/messages/missing-document-component' 'Read how to fix here: https://nextjs.org/docs/messages/missing-document-component'
) )
}
} }
const [renderTargetPrefix, renderTargetSuffix] = documentHTML.split( const [renderTargetPrefix, renderTargetSuffix] = documentHTML.split(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment