forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve automatic prerendering warning (vercel#7759)
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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() { | ||
// ... | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters