@@ -1714,9 +1714,9 @@ export function broadcast(fn) {
17141714// a BigInt throws), so two callers with different arguments would share one
17151715// render. Encodings that differ for equal values only cost sharing. A POST
17161716// body is keyed with its content type; one this dispatch didn't buffer has no
1717- // key, and the call is served per connection.
1718- function encodedArguments ( request , argsEncoding , argumentBytes ) {
1719- if ( request . method !== "POST" ) return argsEncoding || "" ;
1717+ // key, and the call is served per connection. A read without args is keyed by its form query.
1718+ function encodedArguments ( request , url , argsEncoding , argumentBytes ) {
1719+ if ( request . method !== "POST" ) return argsEncoding || url . search ;
17201720 if ( ! argumentBytes ) return undefined ;
17211721 return (
17221722 ( request . headers . get ( "content-type" ) || "" ) +
@@ -4880,7 +4880,7 @@ export async function handleServerFunctionRequest(request, options = {}) {
48804880 id : functionId ,
48814881 live : ! ! live ,
48824882 broadcast : shared || undefined ,
4883- shareKey : shared ? encodedArguments ( request , argsEncoding , argumentBytes ) : undefined
4883+ shareKey : shared ? encodedArguments ( request , url , argsEncoding , argumentBytes ) : undefined
48844884 } ) ;
48854885 const run = ( ) => serverFunction ( ...parsed ) ;
48864886 // Same observation as the direct leg (see `observeInvocation`): the
@@ -4986,11 +4986,8 @@ export async function handleServerFunctionRequest(request, options = {}) {
49864986 // to prefer, a returned `null` passes through as the outcome it is
49874987 // rather than eroding to `undefined` on the way to the flash (#3248).
49884988 if ( handleNoJS ) {
4989- return handleNoJS (
4990- result == null && metadata !== undefined ? metadata : result ,
4991- request ,
4992- parsed
4993- ) ;
4989+ const outcome = result == null && metadata !== undefined ? metadata : result ;
4990+ return withEnvelopeCookies ( await handleNoJS ( outcome , request , parsed ) , outcome , metadata ) ;
49944991 }
49954992 if ( result instanceof Response ) return result ;
49964993 // the envelope's status forwards for unscripted callers too — this
@@ -5141,7 +5138,14 @@ export async function handleServerFunctionRequest(request, options = {}) {
51415138 // `x` was nulled when the thrown Response had no body, but the no-JS
51425139 // handler reads redirect metadata off the result — hand it the
51435140 // original Response, matching what the returned path passes.
5144- if ( handleNoJS ) return handleNoJS ( x ?? metadata , request , parsed , true ) ;
5141+ if ( handleNoJS ) {
5142+ const outcome = x ?? metadata ;
5143+ return withEnvelopeCookies (
5144+ await handleNoJS ( outcome , request , parsed , true ) ,
5145+ outcome ,
5146+ metadata
5147+ ) ;
5148+ }
51455149 if ( x instanceof Response ) return x ;
51465150 }
51475151 if ( scripted && status === 304 ) warnScripted304 ( functionId ) ;
@@ -5249,6 +5253,19 @@ function withholdTrace(event) {
52495253 traceForEvent ( event ) . emit = false ;
52505254}
52515255
5256+ // The no-JS handler sees only an envelope's value, so carry its cookies.
5257+ function withEnvelopeCookies ( response , outcome , metadata ) {
5258+ if ( outcome === metadata || ! metadata || ! metadata . headers || ! ( response instanceof Response ) ) {
5259+ return response ;
5260+ }
5261+ const cookies = metadata . headers . getSetCookie ? metadata . headers . getSetCookie ( ) : [ ] ;
5262+ if ( ! cookies . length ) return response ;
5263+ const owned = ownResponse ( response ) ;
5264+ if ( owned === response ) return response ;
5265+ for ( const cookie of cookies ) owned . headers . append ( "Set-Cookie" , cookie ) ;
5266+ return owned ;
5267+ }
5268+
52525269// A fresh Response around the same body: status, statusText and headers are
52535270// copied (Response doubles as its own ResponseInit), so the copy's headers
52545271// are mutable even when the source's were immutable (Response.redirect, a
0 commit comments