-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
revalidatePath / single Server request with updated rsc data #85
Comments
Hi! Sadly, this is not possible right now in the same way as in Next.js. When calling a server function from a client component by a function call, the request will expect a JSON response from the server. While using a server function as a form action, it is actually a page (or outlet) refresh using an RSC payload response. So, the workaround is to use a form action instead of importing the server function in the client component and just calling it. You can render the arguments of the server function into a hidden input element to send the trimmed value. Another option is to use a client component to render the new item and you can also include
I think that react-server provides a more traditional approach. The function call is like an API call, just returning the data sent by the server function and using a server function as a form action is refreshing the page like with plain HTML forms. Where react-server could improve is in supporting more server function return types, like binary data and even other types of transports, like WebSocket or SSE. |
But why will |
Have a look at the Waku RSC framework as they have implemented a solution to this problem: Providing single request mutation call with UI updates is an important feature of a RSC framework as this gives it a big performance advantage compared to other data loading solutions. When look at the server function from Next.js, they allow to return any standard response object. |
I've found your issue with using Refresh, navigation, and any client-side routing should work as expected, and using any RSC payload to inject into a You can also implement single roundtrip mutations by using form actions instead of directly calling the server function and when the request payload is a What's missing is the capability to simultaneously return any arbitrary value from the server function and re-render the page/outlet and the ability to give the intent to request this from the framework. I think that what Next.js is doing is that it injects the return value of the server function into the RSC payload and then it handles the combined RSC payload on the client. Nothing is impossible here and also it would be easy to add a framework API to give this intent in the server function, similar to how redirect or cache invalidation works. I'll fix the issue with handling a server function return value when it's a |
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.
@aheissenberger as the linked PR describes it, I ended up using an RSC payload for all server functions to support as many return types as possible (including React components), and this also enabled implementing |
This issue has been locked since it has been closed for more than 30 days. If you have found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest version of @lazarv/react-server. If you have any other comments you should create a new discussion. |
Describe the bug
When using Next.js it is possible to call a server action and update the interface with one network request.
The request to the server will contain the payload and the response will return the result of the server function and the update serialized data of the components.
The interface in Next.js ist updated based on the use of
revalidatePath('/')
in the server actionaddTodo()
.How can I achieve this with the react-server framework? I tried to use
refresh()
which should reload the navigation including data from the server and leads with Next.js and other frameworks to an extra request to the server to update the interface. The goal should be to removerefresh()
and only userevalidatePath('/')
in the server action.Next.js 15 todo app:
https://github.com/aheissenberger/demo-nextjs-todo
Request Payload by the Next.js 15 framework:
![SCR-20241204-svfr](https://private-user-images.githubusercontent.com/200095/392561735-7aa7c6d2-8a3d-4386-8205-6e357b9fecfc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg3NzkyOTEsIm5iZiI6MTczODc3ODk5MSwicGF0aCI6Ii8yMDAwOTUvMzkyNTYxNzM1LTdhYTdjNmQyLThhM2QtNDM4Ni04MjA1LTZlMzU3YjlmZWNmYy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwNVQxODA5NTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02ZWUyZWZjMDc2ZDMyNDI4ZGRlOWZhMDliZjJmMjVhMTA0NTRhNTYyNzg2Y2M0YzQ3NTY1NGFhNWY4YmZiOGIwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.3Jk03jR_GKAaUgsfmHWDohnGUWhxSemyDjkH4hhnBj8)
![SCR-20241204-svja](https://private-user-images.githubusercontent.com/200095/392561787-1ad17c24-5528-4378-b19a-8f33b06b41c1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg3NzkyOTEsIm5iZiI6MTczODc3ODk5MSwicGF0aCI6Ii8yMDAwOTUvMzkyNTYxNzg3LTFhZDE3YzI0LTU1MjgtNDM3OC1iMTlhLThmMzNiMDZiNDFjMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwNVQxODA5NTFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iZWJjN2Q3Nzk5YjJjMmJhNjFlMmUyMTdjZjRjNTBkZGE5Y2U2OGM2OTAwMThjMmI0YTdlMGE2MTFiNTljMGQxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.ZkMuBo3m3SORO2gaEH8crX-kkwmDn70CO2pLeqouDPE)
Request Response:
Reproduction
https://github.com/aheissenberger/demo-react-server-todo
Steps to reproduce
No response
System Info
System: OS: macOS 15.1.1 CPU: (12) arm64 Apple M4 Pro Memory: 1.08 GB / 48.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 23.3.0 - /opt/homebrew/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.9.0 - /opt/homebrew/bin/npm pnpm: 9.14.4 - /opt/homebrew/bin/pnpm bun: 1.1.38 - /opt/homebrew/bin/bun Browsers: Chrome: 131.0.6778.108 Safari: 18.1.1 Safari Technology Preview: 18.2 npmPackages: @lazarv/react-server: 0.0.0-experimental-61cbefd-20241204-b7fff15a => 0.0.0-experimental-61cbefd-20241204-b7fff15a
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: