From 2aa85ecb0ac82f47d6d6cb162404de426b95e718 Mon Sep 17 00:00:00 2001 From: Muhammed Al-Dulaimi Date: Fri, 21 Nov 2025 19:10:11 +0300 Subject: [PATCH 1/6] Update get-initial-props.mdx Closes https://github.com/vercel/next.js/issues/86386 --- .../04-api-reference/03-functions/get-initial-props.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index aee5281d1741b..dfeb439832f42 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -6,7 +6,6 @@ description: Fetch dynamic data on the server for your React component with getI > **Good to know**: `getInitialProps` is a legacy API. We recommend using [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) or [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) instead. `getInitialProps` is an `async` function that can be added to the default exported React component for the page. It will run on both the server-side and again on the client-side during page transitions. The result of the function will be forwarded to the React component as `props`. - ```tsx filename="pages/index.tsx" switcher import { NextPageContext } from 'next' @@ -20,7 +19,6 @@ export default function Page({ stars }: { stars: number }) { return stars } ``` - ```jsx filename="pages/index.js" switcher Page.getInitialProps = async (ctx) => { const res = await fetch('https://api.github.com/repos/vercel/next.js') @@ -36,7 +34,10 @@ export default function Page({ stars }) { > **Good to know**: > > - Data returned from `getInitialProps` is serialized when server rendering. Ensure the returned object from `getInitialProps` is a plain `Object`, and not using `Date`, `Map` or `Set`. -> - For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then also run on the client when navigating to a different route with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router). +> - For the initial page load, `getInitialProps` will run on the server only. +> - **When navigating to a different route** with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router): +> - If the page being navigated to **does not have** `getServerSideProps`, then `getInitialProps` will run on the **client-side only**. +> - If the page being navigated to **does have** `getServerSideProps`, then `getInitialProps` will run on the **server-side only** (both `getInitialProps` and `getServerSideProps` execute server-side). > - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will also run on the server. ## Context Object From 657c269ef687613b2bde498425f163f1b2b00ba0 Mon Sep 17 00:00:00 2001 From: Muhammed Al-Dulaimi Date: Mon, 24 Nov 2025 13:35:22 +0300 Subject: [PATCH 2/6] Update docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx Co-authored-by: Joseph --- .../04-api-reference/03-functions/get-initial-props.mdx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index dfeb439832f42..71d6532896c69 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -34,11 +34,7 @@ export default function Page({ stars }) { > **Good to know**: > > - Data returned from `getInitialProps` is serialized when server rendering. Ensure the returned object from `getInitialProps` is a plain `Object`, and not using `Date`, `Map` or `Set`. -> - For the initial page load, `getInitialProps` will run on the server only. -> - **When navigating to a different route** with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router): -> - If the page being navigated to **does not have** `getServerSideProps`, then `getInitialProps` will run on the **client-side only**. -> - If the page being navigated to **does have** `getServerSideProps`, then `getInitialProps` will run on the **server-side only** (both `getInitialProps` and `getServerSideProps` execute server-side). -> - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will also run on the server. + > - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will **only** run on the server. ## Context Object From e8c93c852e12fdfcb2970f851fa8f3c482918abc Mon Sep 17 00:00:00 2001 From: Muhammed Al-Dulaimi Date: Mon, 24 Nov 2025 13:37:14 +0300 Subject: [PATCH 3/6] Update get-initial-props.mdx --- .../02-pages/04-api-reference/03-functions/get-initial-props.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index 71d6532896c69..799d9764f624e 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -34,6 +34,7 @@ export default function Page({ stars }) { > **Good to know**: > > - Data returned from `getInitialProps` is serialized when server rendering. Ensure the returned object from `getInitialProps` is a plain `Object`, and not using `Date`, `Map` or `Set`. +> - For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then also run on the client when navigating to a different route with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router). > - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will **only** run on the server. ## Context Object From a6d2267c70086a513703fa8383fb2a0f7cde56ab Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 24 Nov 2025 13:06:18 +0100 Subject: [PATCH 4/6] fix: formatting on list --- .../04-api-reference/03-functions/get-initial-props.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index 799d9764f624e..8ee7b11a5d4c4 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -35,7 +35,7 @@ export default function Page({ stars }) { > > - Data returned from `getInitialProps` is serialized when server rendering. Ensure the returned object from `getInitialProps` is a plain `Object`, and not using `Date`, `Map` or `Set`. > - For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then also run on the client when navigating to a different route with the [`next/link`](/docs/pages/api-reference/components/link) component or by using [`next/router`](/docs/pages/api-reference/functions/use-router). - > - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will **only** run on the server. +> - If `getInitialProps` is used in a custom `_app.js`, and the page being navigated to is using `getServerSideProps`, then `getInitialProps` will **only** run on the server. ## Context Object From 96cf0b5757c5b5b454a3109f9b36928b44a2c55c Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 24 Nov 2025 13:51:32 +0100 Subject: [PATCH 5/6] docs: more lint fixes --- .../02-pages/04-api-reference/03-functions/get-initial-props.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index 8ee7b11a5d4c4..b7f8e692b461d 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -6,6 +6,7 @@ description: Fetch dynamic data on the server for your React component with getI > **Good to know**: `getInitialProps` is a legacy API. We recommend using [`getStaticProps`](/docs/pages/building-your-application/data-fetching/get-static-props) or [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) instead. `getInitialProps` is an `async` function that can be added to the default exported React component for the page. It will run on both the server-side and again on the client-side during page transitions. The result of the function will be forwarded to the React component as `props`. + ```tsx filename="pages/index.tsx" switcher import { NextPageContext } from 'next' From ec04c6d203d8f1b681dcbfe59748eba33887f807 Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 24 Nov 2025 13:51:58 +0100 Subject: [PATCH 6/6] docs: one more lint fix between snippets --- .../02-pages/04-api-reference/03-functions/get-initial-props.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx index b7f8e692b461d..6f94d5156e5e0 100644 --- a/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx +++ b/docs/02-pages/04-api-reference/03-functions/get-initial-props.mdx @@ -20,6 +20,7 @@ export default function Page({ stars }: { stars: number }) { return stars } ``` + ```jsx filename="pages/index.js" switcher Page.getInitialProps = async (ctx) => { const res = await fetch('https://api.github.com/repos/vercel/next.js')