Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
9b22dc46
Unverified
Commit
9b22dc46
authored
Sep 12, 2020
by
Joe Haddad
Committed by
GitHub
Sep 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve custom document error message (#17048)
parent
9adf3bb6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
14 deletions
+15
-14
render.tsx
packages/next/next-server/server/render.tsx
+10
-9
index.test.js
...ation/missing-document-component-error/test/index.test.js
+5
-5
No files found.
packages/next/next-server/server/render.tsx
View file @
9b22dc46
...
@@ -2,6 +2,7 @@ import { IncomingMessage, ServerResponse } from 'http'
...
@@ -2,6 +2,7 @@ import { IncomingMessage, ServerResponse } from 'http'
import
{
ParsedUrlQuery
}
from
'querystring'
import
{
ParsedUrlQuery
}
from
'querystring'
import
React
from
'react'
import
React
from
'react'
import
{
renderToStaticMarkup
,
renderToString
}
from
'react-dom/server'
import
{
renderToStaticMarkup
,
renderToString
}
from
'react-dom/server'
import
{
warn
}
from
'../../build/output/log'
import
{
UnwrapPromise
}
from
'../../lib/coalesced-function'
import
{
UnwrapPromise
}
from
'../../lib/coalesced-function'
import
{
import
{
GSP_NO_RETURNED_VALUE
,
GSP_NO_RETURNED_VALUE
,
...
@@ -19,9 +20,9 @@ import { isInAmpMode } from '../lib/amp'
...
@@ -19,9 +20,9 @@ import { isInAmpMode } from '../lib/amp'
import
{
AmpStateContext
}
from
'../lib/amp-context'
import
{
AmpStateContext
}
from
'../lib/amp-context'
import
{
import
{
AMP_RENDER_TARGET
,
AMP_RENDER_TARGET
,
PERMANENT_REDIRECT_STATUS
,
SERVER_PROPS_ID
,
SERVER_PROPS_ID
,
STATIC_PROPS_ID
,
STATIC_PROPS_ID
,
PERMANENT_REDIRECT_STATUS
,
TEMPORARY_REDIRECT_STATUS
,
TEMPORARY_REDIRECT_STATUS
,
}
from
'../lib/constants'
}
from
'../lib/constants'
import
{
defaultHead
}
from
'../lib/head'
import
{
defaultHead
}
from
'../lib/head'
...
@@ -37,13 +38,13 @@ import {
...
@@ -37,13 +38,13 @@ import {
AppType
,
AppType
,
ComponentsEnhancer
,
ComponentsEnhancer
,
DocumentInitialProps
,
DocumentInitialProps
,
DocumentProps
,
DocumentType
,
DocumentType
,
getDisplayName
,
getDisplayName
,
isResSent
,
isResSent
,
loadGetInitialProps
,
loadGetInitialProps
,
NextComponentType
,
NextComponentType
,
RenderPage
,
RenderPage
,
DocumentProps
,
}
from
'../lib/utils'
}
from
'../lib/utils'
import
{
tryGetPreviewData
,
__ApiPreviewProps
}
from
'./api-utils'
import
{
tryGetPreviewData
,
__ApiPreviewProps
}
from
'./api-utils'
import
{
denormalizePagePath
}
from
'./denormalize-page-path'
import
{
denormalizePagePath
}
from
'./denormalize-page-path'
...
@@ -906,13 +907,13 @@ export async function renderToHTML(
...
@@ -906,13 +907,13 @@ export async function renderToHTML(
const
plural
=
nonRenderedComponents
.
length
!==
1
?
's'
:
''
const
plural
=
nonRenderedComponents
.
length
!==
1
?
's'
:
''
if
(
nonRenderedComponents
.
length
)
{
if
(
nonRenderedComponents
.
length
)
{
cons
ole
.
warn
(
cons
t
missingComponentList
=
nonRenderedComponents
`Expected Document Component
${
plural
}
${
nonRenderedComponents
.
join
(
.
map
((
e
)
=>
`<
${
e
}
/>`
)
', '
.
join
(
', '
)
)}
${
warn
(
plural
?
'were'
:
'was'
`Your custom Document (pages/_document) did not render all the required subcomponent
${
plural
}
.\n`
+
}
not rendered. Make sure you render them in your custom \`_document\`
\n`
+
`Missing component
${
plural
}
:
${
missingComponentList
}
\n`
+
`See more info here https://err.sh/next.js/missing-document-component`
'Read how to fix here: https://err.sh/next.js/missing-document-component'
)
)
}
}
}
}
...
...
test/integration/missing-document-component-error/test/index.test.js
View file @
9b22dc46
...
@@ -40,7 +40,7 @@ const checkMissing = async (missing = [], docContent) => {
...
@@ -40,7 +40,7 @@ const checkMissing = async (missing = [], docContent) => {
describe
(
'Missing _document components error'
,
()
=>
{
describe
(
'Missing _document components error'
,
()
=>
{
it
(
'should detect missing Html component'
,
async
()
=>
{
it
(
'should detect missing Html component'
,
async
()
=>
{
await
checkMissing
(
await
checkMissing
(
[
'
Html
'
],
[
'
<Html />
'
],
`
`
import Document, { Head, Main, NextScript } from 'next/document'
import Document, { Head, Main, NextScript } from 'next/document'
...
@@ -65,7 +65,7 @@ describe('Missing _document components error', () => {
...
@@ -65,7 +65,7 @@ describe('Missing _document components error', () => {
it
(
'should detect missing Head component'
,
async
()
=>
{
it
(
'should detect missing Head component'
,
async
()
=>
{
await
checkMissing
(
await
checkMissing
(
[
'
Head
'
],
[
'
<Head />
'
],
`
`
import Document, { Html, Main, NextScript } from 'next/document'
import Document, { Html, Main, NextScript } from 'next/document'
...
@@ -89,7 +89,7 @@ describe('Missing _document components error', () => {
...
@@ -89,7 +89,7 @@ describe('Missing _document components error', () => {
it
(
'should detect missing Main component'
,
async
()
=>
{
it
(
'should detect missing Main component'
,
async
()
=>
{
await
checkMissing
(
await
checkMissing
(
[
'
Main
'
],
[
'
<Main />
'
],
`
`
import Document, { Html, Head, NextScript } from 'next/document'
import Document, { Html, Head, NextScript } from 'next/document'
...
@@ -113,7 +113,7 @@ describe('Missing _document components error', () => {
...
@@ -113,7 +113,7 @@ describe('Missing _document components error', () => {
it
(
'should detect missing NextScript component'
,
async
()
=>
{
it
(
'should detect missing NextScript component'
,
async
()
=>
{
await
checkMissing
(
await
checkMissing
(
[
'
NextScript
'
],
[
'
<NextScript />
'
],
`
`
import Document, { Html, Head, Main } from 'next/document'
import Document, { Html, Head, Main } from 'next/document'
...
@@ -136,7 +136,7 @@ describe('Missing _document components error', () => {
...
@@ -136,7 +136,7 @@ describe('Missing _document components error', () => {
it
(
'should detect multiple missing document components'
,
async
()
=>
{
it
(
'should detect multiple missing document components'
,
async
()
=>
{
await
checkMissing
(
await
checkMissing
(
[
'
Head'
,
'NextScript
'
],
[
'
<Head />'
,
'<NextScript />
'
],
`
`
import Document, { Html, Main } from 'next/document'
import Document, { Html, Main } from 'next/document'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment