Q7: What is getInitialProps and why is it generally discouraged in modern Pages Router apps?

getInitialProps was the original data fetching method in Next.js. It runs on both server (initial load) and client (route transitions). Disadvantage: using getInitialProps in _app.js disables Automatic Static Optimization for the entire application.

Key Takeaways
  • Executes on server during initial load and on client during navigation.

  • Disables global Automatic Static Optimization if placed in _app.js.

Knowledge Check

What is the main side effect of defining getInitialProps inside pages/_app.js?