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,6 +1375,7 @@ export async function renderToHTML( ...@@ -1375,6 +1375,7 @@ export async function renderToHTML(
documentHTML = ReactDOMServer.renderToStaticMarkup(document) documentHTML = ReactDOMServer.renderToStaticMarkup(document)
} }
if (process.env.NODE_ENV !== 'production') {
const nonRenderedComponents = [] const nonRenderedComponents = []
const expectedDocComponents = ['Main', 'Head', 'NextScript', 'Html'] const expectedDocComponents = ['Main', 'Head', 'NextScript', 'Html']
...@@ -1389,12 +1390,13 @@ export async function renderToHTML( ...@@ -1389,12 +1390,13 @@ export async function renderToHTML(
.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(
/<next-js-internal-body-render-target><\/next-js-internal-body-render-target>/ /<next-js-internal-body-render-target><\/next-js-internal-body-render-target>/
......
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