@@ -46,7 +46,7 @@ const {readFile} = require('fs').promises;
4646
4747const React = require ( 'react' ) ;
4848
49- async function renderApp ( res , returnValue ) {
49+ async function renderApp ( res , returnValue , formState ) {
5050 const { renderToPipeableStream} = await import (
5151 'react-server-dom-webpack/server'
5252 ) ;
@@ -93,13 +93,13 @@ async function renderApp(res, returnValue) {
9393 React . createElement ( App ) ,
9494 ] ;
9595 // For client-invoked server actions we refresh the tree and return a return value.
96- const payload = returnValue ? { returnValue, root } : root ;
96+ const payload = { root , returnValue, formState } ;
9797 const { pipe} = renderToPipeableStream ( payload , moduleMap ) ;
9898 pipe ( res ) ;
9999}
100100
101101app . get ( '/' , async function ( req , res ) {
102- await renderApp ( res , null ) ;
102+ await renderApp ( res , null , null ) ;
103103} ) ;
104104
105105app . post ( '/' , bodyParser . text ( ) , async function ( req , res ) {
@@ -108,6 +108,7 @@ app.post('/', bodyParser.text(), async function (req, res) {
108108 decodeReply,
109109 decodeReplyFromBusboy,
110110 decodeAction,
111+ decodeFormState,
111112 } = await import ( 'react-server-dom-webpack/server' ) ;
112113 const serverReference = req . get ( 'rsc-action' ) ;
113114 if ( serverReference ) {
@@ -139,7 +140,7 @@ app.post('/', bodyParser.text(), async function (req, res) {
139140 // We handle the error on the client
140141 }
141142 // Refresh the client and return the value
142- renderApp ( res , result ) ;
143+ renderApp ( res , result , null ) ;
143144 } else {
144145 // This is the progressive enhancement case
145146 const UndiciRequest = require ( 'undici' ) . Request ;
@@ -153,12 +154,14 @@ app.post('/', bodyParser.text(), async function (req, res) {
153154 const action = await decodeAction ( formData ) ;
154155 try {
155156 // Wait for any mutations
156- await action ( ) ;
157+ const result = await action ( ) ;
158+ const formState = decodeFormState ( result , formData ) ;
159+ renderApp ( res , null , formState ) ;
157160 } catch ( x ) {
158161 const { setServerState} = await import ( '../src/ServerState.js' ) ;
159162 setServerState ( 'Error: ' + x . message ) ;
163+ renderApp ( res , null , null ) ;
160164 }
161- renderApp ( res , null ) ;
162165 }
163166} ) ;
164167
0 commit comments