Unverified Commit 12f85871 authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

docs: clarify Cache Components build output (#98274)

## Summary

- Clarify that Cache Components uses PPR for every App Router page,
including pages whose build-time HTML is empty.
- Explain that the current tree-view symbols describe output rather than
a different rendering model: an empty PPR HTML output can show `ƒ` at a
fixed pathname or `◐` on a dynamic-path fallback row.
- Clarify that Cache Components pages do not use `●`; generated paths
from `generateStaticParams` show `○` or `◐` based on their HTML output.
- Clarify that `instant = false` opts out of instant-navigation
validation and, when it is the highest config, static-shell validation
without changing the PPR rendering model.
- Keep the guide's existing structure and examples while correcting
factual wording about TypeScript checking, `generateStaticParams`,
Partial Prefetching, cache lifetime output, and build debugging.
- Remove signposting, filler, and unverified claims in the sections
being corrected.

## Verification

- `pnpm prettier --with-node-modules --ignore-path .prettierignore
--check docs/01-app/02-guides/building.mdx`
- `npx eslint --config eslint.config.mjs
docs/01-app/02-guides/building.mdx`
- `git diff --check`
- Verified with `cacheComponents: true` that a fixed page covered by
`instant = false` prints `ƒ`, writes 0-byte HTML, and remains
`PARTIALLY_STATIC` in the prerender manifest. Removing the opt-out
produces the expected prerender-blocking error.
- Verified that a Cache Components route using `generateStaticParams`
prints an unmarked route group, a `◐` fallback, and a `○` generated
pathname without any `●` row.
- Verified `instant = false` with synchronous runtime values and
`--debug-prerender` source frames against a minimal Cache Components app
using the local Next.js package and webpack.
- Not run: `pnpm lint` (docs-only change; focused formatting, ESLint,
and runtime checks passed).

<!-- NEXT_JS_LLM -->
parent 8ff7f2bd
......@@ -146,7 +146,7 @@ Learn more: https://nextjs.org/docs/messages/blocking-prerender-dynamic
...
```
In `next dev` the stack frame resolves to your source, in both the dev overlay and the terminal. A production build minifies server code, so when the build error alone isn't enough, [`next build --debug-prerender`](/docs/app/guides/building#debugging-build-errors) turns on server source maps and continues past the first failure.
`next dev` shows all validation errors with source-mapped stacks in the overlay and terminal. Production builds minify server code and stop after a route fails. Use [`next build --debug-prerender`](/docs/app/guides/building#debug-prerender-errors) to enable server source maps and continue checking other routes.
The `Learn more` link resolves to a per-error page under [`/docs/messages`](https://nextjs.org/docs/messages/blocking-prerender-dynamic) written for agents to read. Each page follows the same shape, with the canonical patterns for every fix, the trade-offs against the other fixes, and the gotchas an agent is likely to miss on a first attempt. The [Instant navigation guide](/docs/app/guides/instant-navigation#ai-workflow) walks through the full loop an agent runs on these errors, from reading the insight to writing an `instant()` test that fails before the fix and passes once it's in place.
......
This diff is collapsed.
......@@ -7,7 +7,9 @@ related:
version: experimental
---
The **forbidden** file is used to render UI when the [`forbidden`](/docs/app/api-reference/functions/forbidden) function is invoked during authentication. Along with allowing you to customize the UI, Next.js will return a `403` status code.
The **forbidden** file renders UI when the [`forbidden`](/docs/app/api-reference/functions/forbidden) function is invoked.
Before streaming starts, Next.js returns a `403` status code. After streaming starts, the status code remains `200` and the forbidden UI renders in the response. Next.js injects a `<meta name="robots" content="noindex" />` tag in both cases. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes) for details.
```tsx filename="app/forbidden.tsx" switcher
import Link from 'next/link'
......
......@@ -98,26 +98,26 @@ In the [component hierarchy](/docs/app/getting-started/project-structure#compone
- Otherwise, [streaming metadata](/docs/app/api-reference/functions/generate-metadata#streaming-metadata) may be used. Next.js automatically detects user agents to choose between blocking and streaming behavior.
- Since streaming is server-rendered, it does not impact SEO. You can use the [Rich Results Test](https://search.google.com/test/rich-results) 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
### Status codes
When streaming, a `200` status code will be returned to signal that the request was successful.
Streaming page responses begin with a `200` status code.
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). Because the response headers have already been sent to the client, the status code of the response cannot be updated.
The initial response headers set the status for the rest of the response. Next.js can then stream redirects and HTTP access fallbacks with [`redirect`](/docs/app/api-reference/functions/redirect), [`notFound`](/docs/app/api-reference/functions/not-found), [`forbidden`](/docs/app/api-reference/functions/forbidden), or [`unauthorized`](/docs/app/api-reference/functions/unauthorized).
For example, when a 404 page is streamed to the client, Next.js includes a `<meta name="robots" content="noindex">` tag in the streamed HTML. This prevents search engines from indexing that URL even if the HTTP status is 200. See Google’s guidance on the [`robots` meta tag](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag).
Some crawlers may label these responses as “soft 404s”. In the streaming case, this does not lead to indexation because the page is explicitly marked `noindex` in the HTML.
Some crawlers may label these responses as “soft 404s”. The `noindex` tag keeps them out of search results.
If you need a 404 status, for compliance or analytics, ensure the resource exists before the response body is streamed, so that the server can set the HTTP status code.
Run the corresponding check before the response body streams to return a `404`, `403`, or `401` status for compliance or analytics.
You can run this check in [`proxy`](/docs/app/api-reference/file-conventions/proxy) to rewrite missing slugs to a not-found route, or [produce a 404 response](/docs/app/api-reference/file-conventions/proxy#producing-a-response). Keep proxy checks fast, and avoid fetching full content there.
For a `404`, you can check the slug in [Proxy](/docs/app/api-reference/file-conventions/proxy), then rewrite it to a not-found route or [return a `404` response](/docs/app/api-reference/file-conventions/proxy#producing-a-response). Keep Proxy checks fast, and avoid fetching full content there.
<details>
<summary>When is the response body streamed?</summary>
The response body starts streaming when a Suspense fallback renders (for example, a `loading.tsx`) or when a Server Component suspends under a `Suspense` boundary. Place `notFound()` before those boundaries and before any `await` that may suspend.
The response body starts streaming when a Suspense fallback renders (for example, a `loading.tsx`) or when a Server Component suspends under a `<Suspense>` boundary. Calling `notFound()`, `forbidden()`, or `unauthorized()` before this point preserves its `404`, `403`, or `401` status.
To start streaming, the response headers must be set. This is why it is not possible to change the status code after streaming started.
Starting the stream sends the response headers and fixes the status code.
</details>
......
......@@ -10,7 +10,9 @@ Next.js provides two conventions to handle not found cases:
## `not-found.js`
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 (see [Status Codes](/docs/app/api-reference/file-conventions/loading#status-codes) for details about SEO).
The **not-found** file renders UI when the [`notFound`](/docs/app/api-reference/functions/not-found) function is thrown within a route segment.
Before streaming starts, Next.js returns a `404` status code. After streaming starts, the status code remains `200` and the not-found UI renders in the response. Next.js injects a `<meta name="robots" content="noindex" />` tag in both cases. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes) for details.
```tsx filename="app/not-found.tsx" switcher
import Link from 'next/link'
......
......@@ -7,7 +7,9 @@ related:
version: experimental
---
The **unauthorized** file is used to render UI when the [`unauthorized`](/docs/app/api-reference/functions/unauthorized) function is invoked during authentication. Along with allowing you to customize the UI, Next.js will return a `401` status code.
The **unauthorized** file renders UI when the [`unauthorized`](/docs/app/api-reference/functions/unauthorized) function is invoked.
Before streaming starts, Next.js returns a `401` status code. After streaming starts, the status code remains `200` and the unauthorized UI renders in the response. Next.js injects a `<meta name="robots" content="noindex" />` tag in both cases. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes) for details.
```tsx filename="app/unauthorized.tsx" switcher
import Login from '@/app/components/Login'
......
......@@ -182,7 +182,9 @@ export default function Forbidden() {
}
```
The trade-off is the HTTP status code. Because the check runs inside the `<Suspense>` boundary, the response has already begun streaming as a `200`, and the status can't change once streaming has started. This is usually fine for a page, where the user sees the `forbidden` UI regardless. To return a real `403` status, the check has to run before the response streams. With [Cache Components](/docs/app/getting-started/caching), every dynamic route streams a static shell first, so run that check in [`proxy`](/docs/app/api-reference/file-conventions/proxy) instead. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
The response starts streaming from the `<Suspense>` boundary before `forbidden()` runs, so it keeps its `200` status. Next.js adds a `noindex` tag.
Calling `forbidden()` before streaming starts returns a `403`. A page that reaches `forbidden()` during prerendering can remain `○` Static and serve a `403`. A request-time check can run in [Proxy](/docs/app/api-reference/file-conventions/proxy) before the page renders. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
### Role-based route protection
......
......@@ -190,7 +190,9 @@ export default function NotFound() {
}
```
The trade-off is the HTTP status code. Because the check runs inside the `<Suspense>` boundary, the response has already begun streaming as a `200`, and the status can't change once streaming has started. The `noindex` tag keeps a soft 404 out of search results. To return a real `404` status, the resource has to be checked before the response streams. With [Cache Components](/docs/app/getting-started/caching), every dynamic route streams a static shell first, so run that check in [`proxy`](/docs/app/api-reference/file-conventions/proxy) instead. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
The response starts streaming from the `<Suspense>` boundary before `notFound()` runs, so it keeps its `200` status. Next.js adds a `noindex` tag.
Calling `notFound()` before streaming starts returns a `404`. A page that reaches `notFound()` during prerendering can remain `○` Static and serve a `404`. A request-time check can run in [Proxy](/docs/app/api-reference/file-conventions/proxy) before the page renders. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
### Serving a 404 from a Route Handler
......
......@@ -186,7 +186,9 @@ export default function Unauthorized() {
}
```
The trade-off is the HTTP status code. Because the check runs inside the `<Suspense>` boundary, the response has already begun streaming as a `200`, and the status can't change once streaming has started. This is usually fine for a page, where the user sees the `unauthorized` UI regardless. To return a real `401` status, the check has to run before the response streams. With [Cache Components](/docs/app/getting-started/caching), every dynamic route streams a static shell first, so run that check in [`proxy`](/docs/app/api-reference/file-conventions/proxy) instead. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
The response starts streaming from the `<Suspense>` boundary before `unauthorized()` runs, so it keeps its `200` status. Next.js adds a `noindex` tag.
Calling `unauthorized()` before streaming starts returns a `401`. A page that reaches `unauthorized()` during prerendering can remain `○` Static and serve a `401`. A request-time check can run in [Proxy](/docs/app/api-reference/file-conventions/proxy) before the page renders. See [Status codes](/docs/app/api-reference/file-conventions/loading#status-codes).
### Displaying login UI to unauthenticated users
......
......@@ -317,8 +317,12 @@ next build --debug-build-paths="pages/*.tsx"
next build --debug-build-paths="app/**/page.tsx,!app/admin/**"
```
You can combine `--debug-build-paths` with `--debug-prerender` for more detailed prerender diagnostics.
In projects that keep routes under `src/`, paths resolve with or without the `src/` prefix, so both `app/page.tsx` and `src/app/page.tsx` match the same route.
Only matching routes appear in the route table. When you select an App Router route, Next.js also includes the built-in `/_not-found` route.
### Changing the default port
By default, Next.js uses `http://localhost:3000` during development and with `next start`. The default port can be changed with the `-p` option, like so:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment