@@ -50,7 +50,7 @@ const {readFile} = require('fs').promises;
5050
5151const React = require ( 'react' ) ;
5252
53- async function renderApp ( res , returnValue , formState ) {
53+ async function renderApp ( res , returnValue , formState , noCache ) {
5454 const { renderToPipeableStream} = await import (
5555 'react-server-dom-webpack/server'
5656 ) ;
@@ -97,15 +97,15 @@ async function renderApp(res, returnValue, formState) {
9797 key : filename ,
9898 } )
9999 ) ,
100- React . createElement ( App )
100+ React . createElement ( App , { noCache } )
101101 ) ;
102102 // For client-invoked server actions we refresh the tree and return a return value.
103103 const payload = { root, returnValue, formState} ;
104104 const { pipe} = renderToPipeableStream ( payload , moduleMap ) ;
105105 pipe ( res ) ;
106106}
107107
108- async function prerenderApp ( res , returnValue , formState ) {
108+ async function prerenderApp ( res , returnValue , formState , noCache ) {
109109 const { unstable_prerenderToNodeStream : prerenderToNodeStream } = await import (
110110 'react-server-dom-webpack/static'
111111 ) ;
@@ -152,7 +152,7 @@ async function prerenderApp(res, returnValue, formState) {
152152 key : filename ,
153153 } )
154154 ) ,
155- React . createElement ( App , { prerender : true } )
155+ React . createElement ( App , { prerender : true , noCache } )
156156 ) ;
157157 // For client-invoked server actions we refresh the tree and return a return value.
158158 const payload = { root, returnValue, formState} ;
@@ -161,14 +161,17 @@ async function prerenderApp(res, returnValue, formState) {
161161}
162162
163163app . get ( '/' , async function ( req , res ) {
164+ const noCache = req . get ( 'cache-control' ) === 'no-cache' ;
165+
164166 if ( 'prerender' in req . query ) {
165- await prerenderApp ( res , null , null ) ;
167+ await prerenderApp ( res , null , null , noCache ) ;
166168 } else {
167- await renderApp ( res , null , null ) ;
169+ await renderApp ( res , null , null , noCache ) ;
168170 }
169171} ) ;
170172
171173app . post ( '/' , bodyParser . text ( ) , async function ( req , res ) {
174+ const noCache = req . headers [ 'cache-control' ] === 'no-cache' ;
172175 const { decodeReply, decodeReplyFromBusboy, decodeAction, decodeFormState} =
173176 await import ( 'react-server-dom-webpack/server' ) ;
174177 const serverReference = req . get ( 'rsc-action' ) ;
@@ -201,7 +204,7 @@ app.post('/', bodyParser.text(), async function (req, res) {
201204 // We handle the error on the client
202205 }
203206 // Refresh the client and return the value
204- renderApp ( res , result , null ) ;
207+ renderApp ( res , result , null , noCache ) ;
205208 } else {
206209 // This is the progressive enhancement case
207210 const UndiciRequest = require ( 'undici' ) . Request ;
@@ -217,11 +220,11 @@ app.post('/', bodyParser.text(), async function (req, res) {
217220 // Wait for any mutations
218221 const result = await action ( ) ;
219222 const formState = decodeFormState ( result , formData ) ;
220- renderApp ( res , null , formState ) ;
223+ renderApp ( res , null , formState , noCache ) ;
221224 } catch ( x ) {
222225 const { setServerState} = await import ( '../src/ServerState.js' ) ;
223226 setServerState ( 'Error: ' + x . message ) ;
224- renderApp ( res , null , null ) ;
227+ renderApp ( res , null , null , noCache ) ;
225228 }
226229 }
227230} ) ;
0 commit comments