Skip to content

Commit cb30f0a

Browse files
icyJosephleerobfufuShihbgwdwrth
authored
[backport] docs: september improvements and fixes (#83997)
Collects a bunch of docs improvements and fixes. --------- Co-authored-by: Lee Robinson <[email protected]> Co-authored-by: Felix Shih <[email protected]> Co-authored-by: Benjamin Woodruff <[email protected]> Co-authored-by: David <[email protected]> Co-authored-by: Aymeric PINEAU <[email protected]> Co-authored-by: Luca Krebs <[email protected]> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com> Co-authored-by: Rich Haines <[email protected]> Co-authored-by: Mohammad Nedaeifard <[email protected]> Co-authored-by: pontasan <[email protected]> Co-authored-by: Steven <[email protected]> Co-authored-by: Honda Yuto <[email protected]> Co-authored-by: Jiachi Liu <[email protected]> Co-authored-by: ryu <[email protected]> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> Co-authored-by: Lorenzo Palmes <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
1 parent b6a32bb commit cb30f0a

29 files changed

+428
-53
lines changed

docs/01-app/01-getting-started/01-installation.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Then, add the following scripts to your `package.json` file:
6363
```json filename="package.json"
6464
{
6565
"scripts": {
66-
"dev": "next dev",
66+
"dev": "next dev --turbopack",
6767
"build": "next build",
6868
"start": "next start",
6969
"lint": "eslint"
@@ -73,11 +73,13 @@ Then, add the following scripts to your `package.json` file:
7373

7474
These scripts refer to the different stages of developing an application:
7575

76-
- `next dev`: Starts the development server.
76+
- `next dev --turbopack`: Starts the development server using Turbopack.
7777
- `next build`: Builds the application for production.
7878
- `next start`: Starts the production server.
7979
- `eslint`: Runs ESLint.
8080

81+
Turbopack is stable for `dev`. For production builds, Turbopack is in beta. To try it, run `next build --turbopack`. See the [Turbopack docs](/docs/app/api-reference/turbopack) for status and caveats.
82+
8183
<AppOnly>
8284

8385
### Create the `app` directory

docs/01-app/01-getting-started/08-updating-data.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,11 @@ Calling `redirect` [throws](/docs/app/api-reference/functions/redirect#behavior)
393393

394394
### Cookies
395395

396-
You can `get`, `set`, and `delete` cookies inside a Server Action using the [`cookies`](/docs/app/api-reference/functions/cookies) API:
396+
You can `get`, `set`, and `delete` cookies inside a Server Action using the [`cookies`](/docs/app/api-reference/functions/cookies) API.
397+
398+
When you [set or delete](/docs/app/api-reference/functions/cookies#understanding-cookie-behavior-in-server-actions) a cookie in a Server Action, Next.js re-renders the current page and its layouts on the server so the **UI reflects the new cookie value**.
399+
400+
> **Good to know**: The server update applies to the current React tree, re-rendering, mounting, or unmounting components, as needed. Client state is preserved for re-rendered components, and effects re-run if their dependencies changed.
397401
398402
```ts filename="app/actions.ts" switcher
399403
'use server'

docs/01-app/01-getting-started/14-metadata-and-og-images.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const metadata: Metadata = {
5151
description: '...',
5252
}
5353

54-
export default function Page() {}
54+
export default function Layout() {}
5555
```
5656

5757
```jsx filename="app/blog/layout.tsx" switcher
@@ -60,7 +60,7 @@ export const metadata = {
6060
description: '...',
6161
}
6262

63-
export default function Page() {}
63+
export default function Layout() {}
6464
```
6565

6666
You can view a full list of available options, in the [`generateMetadata` documentation](/docs/app/api-reference/functions/generate-metadata#metadata-fields).

docs/01-app/01-getting-started/15-route-handlers-and-middleware.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default function Page() {
109109
return <h1>Hello, Next.js!</h1>
110110
}
111111

112-
// Conflict
112+
// Conflict
113113
// `app/route.ts`
114114
export async function POST(request: Request) {}
115115
```
@@ -119,7 +119,7 @@ export default function Page() {
119119
return <h1>Hello, Next.js!</h1>
120120
}
121121

122-
// Conflict
122+
// Conflict
123123
// `app/route.js`
124124
export async function POST(request) {}
125125
```
@@ -164,7 +164,7 @@ Using fetch with `options.cache`, `options.next.revalidate`, or `options.next.ta
164164

165165
### Convention
166166

167-
Use the file `middleware.ts` (or `.js`) in the root of your project to define Middleware. For example, at the same level as `pages` or `app`, or inside `src` if applicable.
167+
Create a `middleware.ts` (or `.js`) file in the project root, or inside `src` if applicable, so that it is located at the same level as `pages` or `app`.
168168

169169
> **Note**: While only one `middleware.ts` file is supported per project, you can still organize your middleware logic into modules. Break out middleware functionalities into separate `.ts` or `.js` files and import them into your main `middleware.ts` file. This allows for cleaner management of route-specific middleware, aggregated in the `middleware.ts` for centralized control. By enforcing a single middleware file, it simplifies configuration, prevents potential conflicts, and optimizes performance by avoiding multiple middleware layers.
170170

docs/01-app/02-guides/backend-for-frontend.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,15 @@ export function middleware(request) {
647647

648648
## Security
649649

650+
### Working with headers
651+
652+
Be deliberate about where headers go, and avoid directly passing incoming request headers to the outgoing response.
653+
654+
- **Upstream request headers**: In Middleware, `NextResponse.next({ request: { headers } })` modifies the headers your server receives and does not expose them to the client.
655+
- **Response headers**: `new Response(..., { headers })`, `NextResponse.json(..., { headers })`, `NextResponse.next({ headers })`, or `response.headers.set(...)` send headers back to the client. If sensitive values were appended to these headers, they will be visible to clients.
656+
657+
Learn more in [NextResponse headers in Middleware](/docs/app/api-reference/functions/next-response#next).
658+
650659
### Rate limiting
651660

652661
You can implement rate limiting in your Next.js backend. In addition to code-based checks, enable any rate limiting features provided by your host.

docs/01-app/02-guides/content-security-policy.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ export function middleware(request: NextRequest) {
548548
const cspHeader = `
549549
default-src 'self';
550550
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' ${isDev ? "'unsafe-eval'" : ''};
551-
style-src 'self' 'nonce-${nonce}' ${isDev ? "'unsafe-inline'" : ''};
551+
style-src 'self' ${isDev ? "'unsafe-inline'" : `'nonce-${nonce}'`};
552552
img-src 'self' blob: data:;
553553
font-src 'self';
554554
object-src 'none';
@@ -570,7 +570,7 @@ export function middleware(request) {
570570
const cspHeader = `
571571
default-src 'self';
572572
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' ${isDev ? "'unsafe-eval'" : ''};
573-
style-src 'self' 'nonce-${nonce}' ${isDev ? "'unsafe-inline'" : ''};
573+
style-src 'self' ${isDev ? "'unsafe-inline'" : `'nonce-${nonce}'`};
574574
img-src 'self' blob: data:;
575575
font-src 'self';
576576
object-src 'none';

docs/01-app/02-guides/data-security.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ yarn add server-only
251251
pnpm add server-only
252252
```
253253

254+
```bash package="bun"
255+
bun add server-only
256+
```
257+
254258
```ts filename="lib/data.ts"
255259
import 'server-only'
256260

docs/01-app/02-guides/incremental-static-regeneration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Here's how this example works:
9797
3. After 60 seconds has passed, the next request will still return the cached (now stale) page
9898
4. The cache is invalidated and a new version of the page begins generating in the background
9999
5. Once generated successfully, the next request will return the updated page and cache it for subsequent requests
100-
6. If `/blog/26` is requested, and it exists, the page will be generated on-demand. This behavior can be changed by using a different [dynamicParams](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) value. However, if the post does not exist, then 404 is returned.
100+
6. If `/blog/26` is requested, and it exists, the page will be generated on-demand. This behavior can be changed by using a different [dynamicParams](/docs/app/api-reference/file-conventions/route-segment-config#dynamicparams) value. However, if the post does not exist, then 404 is returned.
101101

102102
</AppOnly>
103103

@@ -196,7 +196,7 @@ Here's how this example works:
196196
3. After 60 seconds has passed, the next request will still return the cached (now stale) page
197197
4. The cache is invalidated and a new version of the page begins generating in the background
198198
5. Once generated successfully, the next request will return the updated page and cache it for subsequent requests
199-
6. If `/blog/26` is requested, and it exists, the page will be generated on-demand. This behavior can be changed by using a different [fallback](https://nextjs.org/docs/pages/api-reference/functions/get-static-paths#fallback-false) value. However, if the post does not exist, then 404 is returned.
199+
6. If `/blog/26` is requested, and it exists, the page will be generated on-demand. This behavior can be changed by using a different [fallback](/docs/pages/api-reference/functions/get-static-paths#fallback-false) value. However, if the post does not exist, then 404 is returned.
200200

201201
</PagesOnly>
202202

docs/01-app/02-guides/internationalization.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,4 @@ export default async function RootLayout({ children, params }) {
215215
- [`paraglide-next`](https://inlang.com/m/osslbuzt/paraglide-next-i18n)
216216
- [`lingui`](https://lingui.dev)
217217
- [`tolgee`](https://tolgee.io/apps-integrations/next)
218+
- [`next-intlayer`](https://intlayer.org/doc/environment/nextjs)

docs/01-app/02-guides/local-development.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ It provides detailed information about the time taken for each module to compile
181181
1. Navigate around your application or make edits to files to reproduce the problem.
182182
1. Stop the Next.js development server.
183183
1. A file called `trace-turbopack` will be available in the `.next` folder.
184-
1. You can interpret the file using `next internal trace [path-to-file]`:
184+
1. You can interpret the file using `npx next internal trace [path-to-file]`:
185185

186186
```bash
187-
next internal trace .next/trace-turbopack
187+
npx next internal trace .next/trace-turbopack
188188
```
189189

190190
On versions where `trace` is not available, the command was named `turbo-trace-server`:
191191

192192
```bash
193-
next internal turbo-trace-server .next/trace-turbopack
193+
npx next internal turbo-trace-server .next/trace-turbopack
194194
```
195195

196196
1. Once the trace server is running you can view the trace at https://trace.nextjs.org/.

0 commit comments

Comments
 (0)