Unverified Commit 6fa17b3f authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Improve automatic prerendering warning (#7759)

parent 80b46c1d
# 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() {
// ...
}
}
```
...@@ -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'
) )
} }
} }
......
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