From 6e9f2ab07db96ce41b8961a66c826a9e7d88fba7 Mon Sep 17 00:00:00 2001 From: Aman Mittal Date: Thu, 17 Feb 2022 22:39:49 +0530 Subject: [PATCH 1/4] Add info on rendering an error page when using getServerSideProps --- .../data-fetching/get-server-side-props.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/basic-features/data-fetching/get-server-side-props.md b/docs/basic-features/data-fetching/get-server-side-props.md index 22aa4d77dbf7..9fd00dc015d5 100644 --- a/docs/basic-features/data-fetching/get-server-side-props.md +++ b/docs/basic-features/data-fetching/get-server-side-props.md @@ -19,7 +19,7 @@ export async function getServerSideProps(context) { `getServerSideProps` only runs on server-side and never runs on the browser. If a page uses `getServerSideProps`, then: - When you request this page directly, `getServerSideProps` runs at request time, and this page will be pre-rendered with the returned props -- When you request this page on client-side page transitions through [`next/link`](/docs/api-reference/next/link.md) or [`next/router`](/docs/api-reference/next/router.md), Next.js sends an API request to the server, which runs `getServerSideProps`. +- When you request this page on client-side page transitions through [`next/link`](/docs/api-reference/next/link.md) or [`next/router`](/docs/api-reference/next/router.md), Next.js sends an API request to the server, which runs `getServerSideProps` It then returns `JSON` that contains the result of running `getServerSideProps`, that `JSON` will be used to render the page. All this work will be handled automatically by Next.js, so you don’t need to do anything extra as long as you have `getServerSideProps` defined. @@ -47,8 +47,8 @@ Take the following example. An API route is used to fetch some data from a CMS. If your page contains frequently updating data, and you don’t need to pre-render the data, you can fetch the data on the [client side](/docs/basic-features/data-fetching/client-side.md). An example of this is user-specific data: -- First, immediately show the page without data. Parts of the page can be pre-rendered using Static Generation. You can show loading states for missing data. -- Then, fetch the data on the client side and display it when ready. +- First, immediately show the page without data. Parts of the page can be pre-rendered using Static Generation. You can show loading states for missing data +- Then, fetch the data on the client side and display it when ready This approach works well for user dashboard pages, for example. Because a dashboard is a private, user-specific page, SEO is not relevant and the page doesn’t need to be pre-rendered. The data is frequently updated, which requires request-time data fetching. @@ -74,6 +74,10 @@ export async function getServerSideProps() { export default Page ``` +## Does getServerSideProps render an error page + +If an error is thrown inside `getServerSideProps`, it will show an error page when using `next start`. To display an error page, you must create the `pages/500.js` file. Check out the documentation for [500 page](/docs/advanced-features/custom-error-page#500-page) to learn more on how to create it. +
getServerSideProps API Reference From a0197d45bfb9a4946f866e0172875a1b912a5068 Mon Sep 17 00:00:00 2001 From: Aman Mittal Date: Thu, 17 Feb 2022 23:58:53 +0530 Subject: [PATCH 2/4] Update docs/basic-features/data-fetching/get-server-side-props.md Co-authored-by: JJ Kasper --- docs/basic-features/data-fetching/get-server-side-props.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching/get-server-side-props.md b/docs/basic-features/data-fetching/get-server-side-props.md index 9fd00dc015d5..07a89e7f3a96 100644 --- a/docs/basic-features/data-fetching/get-server-side-props.md +++ b/docs/basic-features/data-fetching/get-server-side-props.md @@ -76,7 +76,7 @@ export default Page ## Does getServerSideProps render an error page -If an error is thrown inside `getServerSideProps`, it will show an error page when using `next start`. To display an error page, you must create the `pages/500.js` file. Check out the documentation for [500 page](/docs/advanced-features/custom-error-page#500-page) to learn more on how to create it. +If an error is thrown inside `getServerSideProps`, it will show the `pages/500.js` file. Check out the documentation for [500 page](/docs/advanced-features/custom-error-page#500-page) to learn more on how to create it. During development this file will not be used and the dev overlay will be shown instead.
From 0ffccfcc128d786af6a744f6d900a418f30e3af3 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 17 Feb 2022 12:54:04 -0600 Subject: [PATCH 3/4] lint-fix --- docs/basic-features/data-fetching/get-server-side-props.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic-features/data-fetching/get-server-side-props.md b/docs/basic-features/data-fetching/get-server-side-props.md index 9702710a209f..dfafb0646b93 100644 --- a/docs/basic-features/data-fetching/get-server-side-props.md +++ b/docs/basic-features/data-fetching/get-server-side-props.md @@ -76,7 +76,7 @@ export default Page ## Does getServerSideProps render an error page -If an error is thrown inside `getServerSideProps`, it will show the `pages/500.js` file. Check out the documentation for [500 page](/docs/advanced-features/custom-error-page#500-page) to learn more on how to create it. During development this file will not be used and the dev overlay will be shown instead. +If an error is thrown inside `getServerSideProps`, it will show the `pages/500.js` file. Check out the documentation for [500 page](/docs/advanced-features/custom-error-page#500-page) to learn more on how to create it. During development this file will not be used and the dev overlay will be shown instead. ## Related From edbcc26973737513d84eeb262d7c6fc8f57118e4 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 17 Feb 2022 12:56:27 -0600 Subject: [PATCH 4/4] re-add note --- docs/basic-features/data-fetching/get-server-side-props.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/basic-features/data-fetching/get-server-side-props.md b/docs/basic-features/data-fetching/get-server-side-props.md index dfafb0646b93..da0463f1fecd 100644 --- a/docs/basic-features/data-fetching/get-server-side-props.md +++ b/docs/basic-features/data-fetching/get-server-side-props.md @@ -80,6 +80,8 @@ If an error is thrown inside `getServerSideProps`, it will show the `pages/500.j ## Related +For more information on what to do next, we recommend the following sections: +