mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
20dc57391e
## Summary Update code block language in [error pages](https://github.com/vercel/next.js/tree/canary/errors). ### Improving Documentation - [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
---
|
|
title: Opt-out of Automatic Static Optimization
|
|
---
|
|
|
|
## Why This Warning Occurred
|
|
|
|
You are using `getInitialProps` in your [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app).
|
|
|
|
This causes **all pages** to be executed on the server -- disabling [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization).
|
|
|
|
## 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 previously copied the [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) example, you may be able to remove your `getInitialProps`.
|
|
|
|
The following `getInitialProps` does nothing and may be removed:
|
|
|
|
```jsx filename="pages/_app.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() {
|
|
// ...
|
|
}
|
|
}
|
|
```
|