Skip to content

Commit 9542b8b

Browse files
authored
Docs/feedback round aug (#82549)
Closes: https://linear.app/vercel/issue/DOC-4949/clarification-redirecting-in-server-actions-to-self, https://linear.app/vercel/issue/DOC-4973/global-error-and-global-not-found-in-prod-checklist Additionally addresses community confusion and feedback around Server Functions initial client side sequential processing.
1 parent 5fa0987 commit 9542b8b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ There are two main ways you can invoke a Server Function:
172172
1. [Forms](#forms) in Server and Client Components
173173
2. [Event Handlers](#event-handlers) and [useEffect](#useeffect) in Client Components
174174

175+
> **Good to know:** Server Functions are designed for server-side mutations. The client currently dispatches and awaits them one at a time. This is an implementation detail and may change. If you need parallel data fetching, use [data fetching](/docs/app/getting-started/fetching-data#server-components) in Server Components, or perform parallel work inside a single Server Function or [Route Handler](/docs/app/guides/backend-for-frontend#manipulating-data).
176+
175177
### Forms
176178

177179
React extends the HTML [`<form>`](https://react.dev/reference/react-dom/components/form) element to allow Server Function to be invoked with the HTML `action` prop.
@@ -355,34 +357,40 @@ export async function createPost(formData) {
355357

356358
### Redirecting
357359

358-
You may want to redirect the user to a different page after performing an update. You can do this by calling [`redirect`](/docs/app/api-reference/functions/redirect) within the Server Function:
360+
You may want to redirect the user to a different page after performing an update. You can do this by calling [`redirect`](/docs/app/api-reference/functions/redirect) within the Server Function.
359361

360362
```ts filename="app/lib/actions.ts" switcher
361363
'use server'
362364

365+
import { revalidatePath } from 'next/cache'
363366
import { redirect } from 'next/navigation'
364367

365368
export async function createPost(formData: FormData) {
366369
// Update data
367370
// ...
368371

372+
revalidatePath('/posts')
369373
redirect('/posts')
370374
}
371375
```
372376

373377
```js filename="app/actions.js" switcher
374378
'use server'
375379

380+
import { revalidatePath } from 'next/cache'
376381
import { redirect } from 'next/navigation'
377382

378383
export async function createPost(formData) {
379384
// Update data
380385
// ...
381386

387+
revalidatePath('/posts')
382388
redirect('/posts')
383389
}
384390
```
385391

392+
Calling `redirect` [throws](/docs/app/api-reference/functions/redirect#behavior) a framework handled control-flow exception. Any code after it won't execute. If you need fresh data, call [`revalidatePath`](/docs/app/api-reference/functions/revalidatePath) or [`revalidateTag`](/docs/app/api-reference/functions/revalidateTag) beforehand.
393+
386394
### Cookies
387395

388396
You can `get`, `set`, and `delete` cookies inside a Server Action using the [`cookies`](/docs/app/api-reference/functions/cookies) API:

docs/01-app/02-guides/production-checklist.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ While building your application, we recommend using the following features to en
8484
<AppOnly>
8585

8686
- **[Forms and Validation](/docs/app/guides/forms):** Use Server Actions to handle form submissions, server-side validation, and handle errors.
87+
- **[Global Error UI](/docs/app/api-reference/file-conventions/error#global-error):** Add `app/global-error.tsx` to provide consistent, accessible fallback UI and recovery for uncaught errors across your app.
88+
- **[Global 404](/docs/app/api-reference/file-conventions/not-found#global-not-foundjs-experimental):** Add `app/global-not-found.tsx` to serve an accessible 404 for unmatched routes across your app.
8789

8890
</AppOnly>
8991

0 commit comments

Comments
 (0)