Buckets:
| --- | |
| 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) file. | |
| This causes **all pages** that do not use [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) into Server-side Rendering (at runtime) and disables [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization). | |
| ## Possible Ways to Fix It | |
| Verify if you need to use `getInitialProps` in `pages/_app`. There are some valid use cases for this, but it's often better to use `getInitialProps` in individual pages. | |
| - Check for any [higher-order components](https://reactjs.org/docs/higher-order-components.html) that may have added `getInitialProps` to your [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app). | |
| - If you previously copied the [Custom `<App>`](/docs/pages/building-your-application/routing/custom-app) example from the old docs, you can remove `getInitialProps`. | |
| The following `getInitialProps` can 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() { | |
| // ... | |
| } | |
| } | |
| ``` | |
Xet Storage Details
- Size:
- 1.47 kB
- Xet hash:
- 455cb17f83d796850396cb168dfff8ccff1914c47ed5cd54f7726aa3f43f8530
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.