Opt-out of Automatic Static Optimization
Why This Warning Occurred​
You are using getInitialProps
in your Custom <App>
file.
This causes all pages that do not use getStaticProps
into Server-side Rendering (at runtime) and disables 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 that may have added
getInitialProps
to your Custom<App>
. - If you previously copied the Custom
<App>
example from the old docs, you can removegetInitialProps
.
The following getInitialProps
can be removed:
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() {
// ...
}
}