2019-07-05 17:57:16 +02:00
|
|
|
# Opt-out of Automatic Prerendering
|
|
|
|
|
|
|
|
#### Why This Warning Occurred
|
|
|
|
|
2019-08-26 16:00:37 +02:00
|
|
|
You are using `getInitialProps` in your [Custom `<App>`](https://nextjs.org/docs#custom-app).
|
2019-07-05 17:57:16 +02:00
|
|
|
|
2019-08-26 16:00:37 +02:00
|
|
|
This causes **all pages** to be executed on the server -- disabling [Automatic Prerendering](https://nextjs.org/docs#automatic-prerendering).
|
2019-07-05 17:57:16 +02:00
|
|
|
|
|
|
|
#### 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.
|
|
|
|
|
2019-09-06 04:37:22 +02:00
|
|
|
If you previously copied the [Custom `<App>`](https://nextjs.org/docs#custom-app) example, you may be able to remove your `getInitialProps`.
|
2019-07-05 17:57:16 +02:00
|
|
|
|
|
|
|
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() {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|