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
6fa17b3f
Unverified
Commit
6fa17b3f
authored
Jul 05, 2019
by
Joe Haddad
Committed by
GitHub
Jul 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve automatic prerendering warning (#7759)
parent
80b46c1d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
opt-out-automatic-prerendering.md
errors/opt-out-automatic-prerendering.md
+35
-0
index.ts
packages/next/build/index.ts
+7
-1
No files found.
errors/opt-out-automatic-prerendering.md
0 → 100644
View file @
6fa17b3f
# Opt-out of Automatic Prerendering
#### Why This Warning Occurred
You are using
`getInitialProps`
in your
[
Custom `<App>`
](
https://github.com/zeit/next.js#custom-app
)
.
This causes
**all pages**
to be executed on the server -- disabling
[
Automatic Prerendering
](
https://github.com/zeit/next.js#automatic-prerendering
)
.
#### Possible Ways to Fix It
Be sure you meant to use
`getInitialProps`
in
`pages/_app`
!
There are some valid use cases for this, but it is often better to handle
`getInitialProps`
on a _per-page_ basis.
If you copied the
[
Custom `<App>`
](
https://github.com/zeit/next.js#custom-app
)
example, you may be able to remove your
`getInitialProps`
.
The following
`getInitialProps`
does nothing and may be removed:
```
js
class
MyApp
extends
App
{
// Remove me, I do nothing!
static
async
getInitialProps
({
Component
,
ctx
})
{
let
pageProps
=
{}
if
(
Component
.
getInitialProps
)
{
pageProps
=
await
Component
.
getInitialProps
(
ctx
)
}
return
{
pageProps
}
}
render
()
{
// ...
}
}
```
packages/next/build/index.ts
View file @
6fa17b3f
...
@@ -329,7 +329,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -329,7 +329,13 @@ export default async function build(dir: string, conf = null): Promise<void> {
if
(
customAppGetInitialProps
)
{
if
(
customAppGetInitialProps
)
{
console
.
warn
(
console
.
warn
(
'Opting out of automatic exporting due to custom `getInitialProps` in `pages/_app`
\
n'
chalk
.
bold
.
yellow
(
`Warning: `
)
+
chalk
.
yellow
(
`You have opted-out of Automatic Prerendering due to \`getInitialProps\` in \`pages/_app\`.`
)
)
console
.
warn
(
'Read more: https://err.sh/next.js/opt-out-automatic-prerendering
\
n'
)
)
}
}
}
}
...
...
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