From 787186a85a054ea870fc964583fe65e9f2286354 Mon Sep 17 00:00:00 2001 From: Aman Mittal Date: Fri, 18 Feb 2022 00:34:08 +0530 Subject: [PATCH] Add info on rendering an error page when using getServerSideProps (#34488) This PR adds information on rendering an error page (500 page specifically) when using `getServerSideProps`. ## Bug - [x] Related issues linked using https://github.com/vercel/documentation/issues/106 - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com> --- .../basic-features/data-fetching/get-server-side-props.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 377a775aa5a2..da0463f1fecd 100644 --- a/docs/basic-features/data-fetching/get-server-side-props.md +++ b/docs/basic-features/data-fetching/get-server-side-props.md @@ -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 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 For more information on what to do next, we recommend the following sections: