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
0cf70618
Unverified
Commit
0cf70618
authored
Nov 17, 2021
by
Gerald Monaco
Committed by
GitHub
Nov 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make missing `Document` components an error (#31505)
* Make missing document components an error * Fix broken tests
parent
9ab17091
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
27 deletions
+25
-27
render.tsx
packages/next/server/render.tsx
+16
-18
_document.js
...font-optimization/fixtures/with-google/pages/_document.js
+3
-3
_document.js
...ont-optimization/fixtures/with-typekit/pages/_document.js
+3
-3
_document.js
test/integration/script-loader/pages/_document.js
+3
-3
No files found.
packages/next/server/render.tsx
View file @
0cf70618
...
...
@@ -1298,27 +1298,25 @@ export async function renderToHTML(
documentHTML
=
ReactDOMServer
.
renderToStaticMarkup
(
document
)
}
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
const
nonRenderedComponents
=
[]
const
expectedDocComponents
=
[
'Main'
,
'Head'
,
'NextScript'
,
'Html'
]
const
nonRenderedComponents
=
[]
const
expectedDocComponents
=
[
'Main'
,
'Head'
,
'NextScript'
,
'Html'
]
for
(
const
comp
of
expectedDocComponents
)
{
if
(
!
(
docComponentsRendered
as
any
)[
comp
])
{
nonRenderedComponents
.
push
(
comp
)
}
for
(
const
comp
of
expectedDocComponents
)
{
if
(
!
(
docComponentsRendered
as
any
)[
comp
])
{
nonRenderedComponents
.
push
(
comp
)
}
const
plural
=
nonRenderedComponents
.
length
!==
1
?
's'
:
''
}
if
(
nonRenderedComponents
.
length
)
{
const
missingComponentList
=
nonRenderedComponents
.
map
((
e
)
=>
`<
${
e
}
/>`
)
.
join
(
', '
)
warn
(
`Your custom Document (pages/_document) did not render all the required subcomponent
${
plural
}
.\n`
+
`Missing component
${
plural
}
:
${
missingComponentList
}
\n`
+
'Read how to fix here: https://nextjs.org/docs/messages/missing-document-component'
)
}
if
(
nonRenderedComponents
.
length
)
{
const
missingComponentList
=
nonRenderedComponents
.
map
((
e
)
=>
`<
${
e
}
/>`
)
.
join
(
', '
)
const
plural
=
nonRenderedComponents
.
length
!==
1
?
's'
:
''
throw
new
Error
(
`Your custom Document (pages/_document) did not render all the required subcomponent
${
plural
}
.
\n`
+
`Missing component
${
plural
}
:
${
missingComponentList
}
\n`
+
'Read how to fix here: https://nextjs.org/docs/messages/missing-document-component'
)
}
const
[
renderTargetPrefix
,
renderTargetSuffix
]
=
documentHTML
.
split
(
...
...
test/integration/font-optimization/fixtures/with-google/pages/_document.js
View file @
0cf70618
import
*
as
React
from
'react'
/// @ts-ignore
import
Document
,
{
Main
,
NextScript
,
Head
}
from
'next/document'
import
Document
,
{
Main
,
NextScript
,
Head
,
Html
}
from
'next/document'
export
default
class
MyDocument
extends
Document
{
constructor
(
props
)
{
super
(
props
)
...
...
@@ -12,7 +12,7 @@ export default class MyDocument extends Document {
render
()
{
return
(
<
h
tml
>
<
H
tml
>
<
Head
>
<
link
rel
=
"stylesheet"
...
...
@@ -24,7 +24,7 @@ export default class MyDocument extends Document {
<
Main
/>
<
NextScript
/>
<
/body
>
<
/
h
tml
>
<
/
H
tml
>
)
}
}
test/integration/font-optimization/fixtures/with-typekit/pages/_document.js
View file @
0cf70618
import
*
as
React
from
'react'
/// @ts-ignore
import
Document
,
{
Main
,
NextScript
,
Head
}
from
'next/document'
import
Document
,
{
Main
,
NextScript
,
Head
,
Html
}
from
'next/document'
export
default
class
MyDocument
extends
Document
{
constructor
(
props
)
{
...
...
@@ -13,7 +13,7 @@ export default class MyDocument extends Document {
render
()
{
return
(
<
h
tml
>
<
H
tml
>
<
Head
>
<
link
rel
=
"stylesheet"
href
=
"https://use.typekit.net/plm1izr.css"
/>
<
/Head
>
...
...
@@ -21,7 +21,7 @@ export default class MyDocument extends Document {
<
Main
/>
<
NextScript
/>
<
/body
>
<
/
h
tml
>
<
/
H
tml
>
)
}
}
test/integration/script-loader/pages/_document.js
View file @
0cf70618
import
*
as
React
from
'react'
/// @ts-ignore
import
Document
,
{
Main
,
NextScript
,
Head
}
from
'next/document'
import
Document
,
{
Main
,
NextScript
,
Head
,
Html
}
from
'next/document'
export
default
class
MyDocument
extends
Document
{
constructor
(
props
)
{
...
...
@@ -13,7 +13,7 @@ export default class MyDocument extends Document {
render
()
{
return
(
<
h
tml
>
<
H
tml
>
<
Head
>
<
link
rel
=
"stylesheet"
...
...
@@ -25,7 +25,7 @@ export default class MyDocument extends Document {
<
NextScript
/>
<
div
id
=
"text"
/>
<
/body
>
<
/
h
tml
>
<
/
H
tml
>
)
}
}
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