You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: server-actions-for-next-pages/README.md
+125Lines changed: 125 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,131 @@ export async function failingFunction({}) {
154
154
}
155
155
```
156
156
157
+
## Aborting requests with AbortSignal
158
+
159
+
You can abort ongoing server actions using `AbortController` and `AbortSignal`. Pass an abort signal in your arguments (either directly or as a field in an object parameter), and it will be used to:
160
+
161
+
-**Client-side**: Abort the fetch request
162
+
-**Server-side**: Allow server functions to respond to request cancellations
**Note**: You can pass `AbortSignal` or `AbortController` directly as arguments, or as fields within object parameters. The server function will receive the request's abort signal, allowing it to detect when the client cancels the request (e.g., when navigating away).
229
+
230
+
## Custom fetch function
231
+
232
+
You can provide a custom `fetch` function to your server actions by including it as a `fetch` field in an object parameter. This is useful for adding custom headers, authentication, or using a custom fetch implementation.
-**Client-side**: If you provide a `fetch` field in an object parameter, it will be used for the RPC call instead of the global `fetch`
279
+
-**Server-side**: The global `fetch` function is automatically injected into object parameters (unless you already provided your own)
280
+
- User-provided fetch functions always take precedence over the injected one
281
+
157
282
## How it works
158
283
159
284
The plugin will replace the content of files inside `pages/api` with `"poor man's use server"` at the top to make the exported functions callable from the browser.
0 commit comments