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
Server functions now return result in RSC payload. This helps with
supporting multiple types of results (including binary formats) and also
enables the new `reload()` API which enables single-roundtrip mutation
and page (or outlet) refresh by combining the server function result
with the rendered component in a single RSC payload.
Includes tests for multiple server function result types and
documentation update to include `reload()`.
This PR addresses an issue with server functions without a return value
(`Promise<void>`) and enhances the framework to be able to return a
rendered component along with the server function return value discussed
in #85.
Copy file name to clipboardExpand all lines: docs/src/pages/en/(pages)/router/server-routing.mdx
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -234,6 +234,36 @@ export default function App() {
234
234
}
235
235
```
236
236
237
+
<Linkname="reload">
238
+
## Reload
239
+
</Link>
240
+
241
+
In server functions, you can use the `reload` function to reload the current page or an outlet. This is useful when you want to reload the page or an outlet after a mutation to refresh the elements in your app.
242
+
243
+
```tsx
244
+
"use server";
245
+
246
+
import { reload } from"@lazarv/react-server";
247
+
248
+
exportasyncfunction addTodo(todo) {
249
+
awaitaddTodo(todo);
250
+
reload();
251
+
}
252
+
```
253
+
254
+
You can also pass an URL and an outlet name to the `reload` function to render a different route and outlet. You can use this approach to optimize the performance of your app by avoiding unnecessary re-renders of the entire app even when using server functions to mutate data.
* Instructs the framework to reload the page or the specified outlet after executing the current server function, using the component rendered at the specified URL.
160
+
* Only usable inside server functions!
161
+
*
162
+
* @param url - Render the component at the specified URL
163
+
* @param outlet - The outlet to reload after rendering the component (defaults to page root)
0 commit comments