Skip to content

Commit

Permalink
Docs: Clarify status codes w/ streaming (#54374)
Browse files Browse the repository at this point in the history
Clarify what status code is returned when streaming, and in relation to `redirect` and `not-found`. 

Relates to: #54361

Co-authored-by: Lee Robinson <[email protected]>
  • Loading branch information
delbaoliveira and leerob authored Aug 22, 2023
1 parent 8bbf674 commit 9ca82f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ For more Suspense examples and use cases, please see the [React Documentation](h

- Next.js will wait for data fetching inside [`generateMetadata`](/docs/app/api-reference/functions/generate-metadata) to complete before streaming UI to the client. This guarantees the first part of a streamed response includes `<head>` tags.
- Since streaming is server-rendered, it does not impact SEO. You can use the [Mobile Friendly Test](https://search.google.com/test/mobile-friendly) tool from Google to see how your page appears to Google's web crawlers and view the serialized HTML ([source](https://web.dev/rendering-on-the-web/#seo-considerations)).

### Status Codes

When streaming, a `200` status code will be returned to signal that the request was successful.

The server can still communicate errors or issues to the client within the streamed content itself, for example, when using [`redirect`](/docs/app/api-reference/functions/redirect) or [`notFound`](/docs/app/api-reference/functions/not-found). Since the response headers have already been sent to the client, the status code of the response cannot be updated. This does not affect SEO.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: not-found.js
description: API reference for the not-found.js file.
---

The **not-found** file is used to render UI when the [`notFound`](/docs/app/api-reference/functions/not-found) function is thrown within a route segment. Along with serving a custom UI, Next.js will also return a `404` HTTP status code.
The **not-found** file is used to render UI when the [`notFound`](/docs/app/api-reference/functions/not-found) function is thrown within a route segment. Along with serving a custom UI, Next.js will return a `200` HTTP status code for streamed responses, and `404` for non-streamed responses.

```tsx filename="app/blog/not-found.tsx" switcher
import Link from 'next/link'
Expand Down
2 changes: 1 addition & 1 deletion docs/02-app/02-api-reference/04-functions/redirect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: API Reference for the redirect function.

The `redirect` function allows you to redirect the user to another URL. `redirect` can be used in Server Components, Client Components, [Route Handlers](/docs/app/building-your-application/routing/route-handlers), and [Server Actions](/docs/app/building-your-application/data-fetching/server-actions).

If you need to redirect to a 404, use the [`notFound` function](/docs/app/api-reference/functions/not-found) instead.
If a resource doesn't exist, you can use the [`notFound` function](/docs/app/api-reference/functions/not-found) instead.

## Parameters

Expand Down

0 comments on commit 9ca82f6

Please sign in to comment.