Unverified Commit c5b8ea43 authored by Joseph's avatar Joseph Committed by GitHub

Instant Navs guide: Highlights fixes and Client Component Page option (#95313)

- Fix/adjust a few code highlights
- Section about `use client` as a fix for soft-nav instant insights
parent c77d47fc
...@@ -72,7 +72,7 @@ By **default** (`validationLevel: 'warning'`), Cache Components apps validate ev ...@@ -72,7 +72,7 @@ By **default** (`validationLevel: 'warning'`), Cache Components apps validate ev
To opt out of automatic validation and only validate segments that explicitly export `instant`, set [`validationLevel`](/docs/app/api-reference/file-conventions/route-segment-config/instant#configuring-validation-defaults) to `'manual-warning'`: To opt out of automatic validation and only validate segments that explicitly export `instant`, set [`validationLevel`](/docs/app/api-reference/file-conventions/route-segment-config/instant#configuring-validation-defaults) to `'manual-warning'`:
```ts filename="next.config.ts" highlight={4-8} ```ts filename="next.config.ts" highlight={7}
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
...@@ -124,7 +124,7 @@ The product page fetches two pieces of data: product details (name, price) and l ...@@ -124,7 +124,7 @@ The product page fetches two pieces of data: product details (name, price) and l
- **Product info** rarely changes and is queried from the db using a cached function - **Product info** rarely changes and is queried from the db using a cached function
- **Inventory** must be fresh on each request. The db query is inside a `<Suspense>` boundary - **Inventory** must be fresh on each request. The db query is inside a `<Suspense>` boundary
```tsx filename="app/store/[slug]/page.tsx" highlight={7-12,30-32} ```tsx filename="app/store/[slug]/page.tsx" highlight={7-12,31}
import { Suspense } from 'react' import { Suspense } from 'react'
import { db } from '@/lib/db' import { db } from '@/lib/db'
...@@ -196,6 +196,12 @@ Cache Components validates this route automatically in development. If something ...@@ -196,6 +196,12 @@ Cache Components validates this route automatically in development. If something
Validation runs on every page load using the real request from your browser, so dynamic params like `[slug]` are checked against actual values as you navigate. Validation runs on every page load using the real request from your browser, so dynamic params like `[slug]` are checked against actual values as you navigate.
### Client Component Pages
A soft navigation into a page with `"use client"` at the top behaves like a single-page app transition, with no server render at navigation time, which makes it instant. The dev overlay doesn't include this in its fix cards because it has bigger implications than the recommended approaches, which keep the page in the server-component model. Reach for `"use client"` when the page is fully interactive and must be a client component.
> **Good to know**: `"use client"` doesn't skip validation for the static shell. Hooks like `useSearchParams()` still need a `<Suspense>` boundary.
## Visualize loading states with the Next.js DevTools ## Visualize loading states with the Next.js DevTools
As you develop a route, the Next.js DevTools let you see what your users see on page loads and client navigations before dynamic data streams in. Use it to verify that your loading states look right, confirm the content you expect appears immediately, and iterate on where to place `<Suspense>` boundaries. As you develop a route, the Next.js DevTools let you see what your users see on page loads and client navigations before dynamic data streams in. Use it to verify that your loading states look right, confirm the content you expect appears immediately, and iterate on where to place `<Suspense>` boundaries.
......
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