[GH-ISSUE #675] getInitialProps support #143

Open
opened 2026-05-06 12:37:36 +02:00 by BreizhHardware · 3 comments

Originally created by @gevgeny on GitHub (Mar 24, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/675

I know getInitialProps is a legacy API but many project still use it. Do you have plans to add support of it?

Originally created by @gevgeny on GitHub (Mar 24, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/675 I know `getInitialProps` is a legacy API but many project still use it. Do you have plans to add support of it?
Author
Owner

@james-elicx commented on GitHub (Mar 24, 2026):

In short, yes. At the moment, though, there's quite a bit of Pages router functionality that doesn't work properly, which I know a lot of older apps will depend on, so it's a goal, but it might take a while to fully get there.

<!-- gh-comment-id:4119720479 --> @james-elicx commented on GitHub (Mar 24, 2026): In short, yes. At the moment, though, there's quite a bit of Pages router functionality that doesn't work properly, which I know a lot of older apps will depend on, so it's a goal, but it might take a while to fully get there.
Author
Owner

@southpolesteve commented on GitHub (Mar 25, 2026):

Genuinely curious about your use case here. getInitialProps is a pretty old API (effectively deprecated since 2020) and I'm pretty hesitant to take on the maintenance burden of supporting it. Before we commit to anything, would love to understand more:

  • What's preventing a migration to getServerSideProps? For most apps it's a mechanical substitution.
  • Is there something specific about the dual server/client execution model you're relying on? If so, Remix's loader API is actually a much better-designed version of that same concept and might be worth considering.
  • What's stopping AI-assisted migration? Honestly this feels like a case where you point Cursor or Claude at the codebase and say "migrate all getInitialProps to getServerSideProps" and it's done in an afternoon. The cost of framework migration in general has dropped dramatically as I said in the original vinext announcement blog.

If you have an app deeply built around the getInitialProps model and you don't want to migrate, it might be worth asking whether Next.js (or vinext) is actually the right tool. The getInitialProps style (one function, runs on both server and client) is closer in spirit to Remix than to where Next.js has gone with the App Router and RSCs. And if none of the modern React stuff (RSCs, server actions, etc.) is relevant to your app, you could probably vibe-code a narrow framework around that API in a day: Preact, a simple SSR handler, skip all the new complexity. You'd end up with something smaller and faster than Next.js ever was.

Happy to reconsider if there's a compelling case we're not seeing.

<!-- gh-comment-id:4122507065 --> @southpolesteve commented on GitHub (Mar 25, 2026): Genuinely curious about your use case here. getInitialProps is a pretty old API (effectively deprecated since 2020) and I'm pretty hesitant to take on the maintenance burden of supporting it. Before we commit to anything, would love to understand more: - What's preventing a migration to getServerSideProps? For most apps it's a mechanical substitution. - Is there something specific about the dual server/client execution model you're relying on? If so, Remix's loader API is actually a much better-designed version of that same concept and might be worth considering. - What's stopping AI-assisted migration? Honestly this feels like a case where you point Cursor or Claude at the codebase and say "migrate all getInitialProps to getServerSideProps" and it's done in an afternoon. The cost of framework migration in general has dropped dramatically as I said in the original vinext announcement blog. If you have an app deeply built around the getInitialProps model and you don't want to migrate, it might be worth asking whether Next.js (or vinext) is actually the right tool. The getInitialProps style (one function, runs on both server and client) is closer in spirit to Remix than to where Next.js has gone with the App Router and RSCs. And if none of the modern React stuff (RSCs, server actions, etc.) is relevant to your app, you could probably vibe-code a narrow framework around that API in a day: Preact, a simple SSR handler, skip all the new complexity. You'd end up with something smaller and faster than Next.js ever was. Happy to reconsider if there's a compelling case we're not seeing.
Author
Owner

@gevgeny commented on GitHub (Mar 25, 2026):

My use case is SSRing styled-component generated styles. Basically this common trick used:

import Document from "next/document";
import { ServerStyleSheet } from "styled-components";

export default class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const sheet = new ServerStyleSheet();
    const originalRenderPage = ctx.renderPage;
    try {
      ctx.renderPage = () =&gt;
        originalRenderPage({
          enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),
        });
      const initialProps = await Document.getInitialProps(ctx);
      return {
        ...initialProps,
        styles: (
          <>
            {initialProps.styles}
            {sheet.getStyleElement()}
          </>
        ),
      };
    } finally {
      sheet.seal();
    }
  }
}

And get getServerSideProps is not available in the Document component. I understand that this code is quite old, but getting rid if getInitialProps would require migrating to the App router, if I understand it right.

<!-- gh-comment-id:4125231360 --> @gevgeny commented on GitHub (Mar 25, 2026): My use case is SSRing styled-component generated styles. Basically this common trick used: ```js import Document from "next/document"; import { ServerStyleSheet } from "styled-components"; export default class MyDocument extends Document { static async getInitialProps(ctx) { const sheet = new ServerStyleSheet(); const originalRenderPage = ctx.renderPage; try { ctx.renderPage = () =&gt; originalRenderPage({ enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />), }); const initialProps = await Document.getInitialProps(ctx); return { ...initialProps, styles: ( <> {initialProps.styles} {sheet.getStyleElement()} </> ), }; } finally { sheet.seal(); } } } ``` And get `getServerSideProps` is not available in the `Document` component. I understand that this code is quite old, but getting rid if `getInitialProps` would require migrating to the App router, if I understand it right.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#143
No description provided.