rsnext/errors/opt-out-auto-static-optimization.md
stefanprobst 279ae19c7e
docs: update links to docs site (#14305)
this updates some links to the docs site to their new location
2020-06-18 09:54:07 +00:00

1.3 KiB

Opt-out of Automatic Static Optimization

Why This Warning Occurred

You are using getInitialProps in your Custom <App>.

This causes all non-getStaticProps pages to be executed on the server -- disabling 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.

Check for any higher-order components that may have added getInitialProps to your Custom <App>.

If you previously copied the Custom <App> example, you may be able to remove your getInitialProps.

The following getInitialProps does nothing and may 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() {
    // ...
  }
}