@@ -131,7 +131,7 @@ export class RenderContext {
131131 componentInstance : ComponentInstance | undefined ,
132132 slots : Record < string , any > = { } ,
133133 ) : Promise < Response > {
134- const { cookies , middleware, pipeline } = this ;
134+ const { middleware, pipeline } = this ;
135135 const { logger, serverLike, streaming, manifest } = pipeline ;
136136
137137 const props =
@@ -271,7 +271,7 @@ export class RenderContext {
271271 // because they may need to be passed along from a rewrite.
272272 const responseCookies = getCookiesFromResponse ( response ) ;
273273 if ( responseCookies ) {
274- cookies . merge ( responseCookies ) ;
274+ this . cookies . merge ( responseCookies ) ;
275275 }
276276 return response ;
277277 } ;
@@ -289,7 +289,7 @@ export class RenderContext {
289289 // LEGACY: we put cookies on the response object,
290290 // where the adapter might be expecting to read it.
291291 // New code should be using `app.render({ addCookieHeader: true })` instead.
292- attachCookiesToResponse ( response , cookies ) ;
292+ attachCookiesToResponse ( response , this . cookies ) ;
293293 return response ;
294294 }
295295
@@ -346,7 +346,11 @@ export class RenderContext {
346346 ) ;
347347 }
348348 this . url = new URL ( this . request . url ) ;
349- this . cookies = new AstroCookies ( this . request ) ;
349+ const newCookies = new AstroCookies ( this . request ) ;
350+ if ( this . cookies ) {
351+ newCookies . merge ( this . cookies ) ;
352+ }
353+ this . cookies = newCookies ;
350354 this . params = getParams ( routeData , pathname ) ;
351355 this . pathname = pathname ;
352356 this . isRewriting = true ;
@@ -363,15 +367,18 @@ export class RenderContext {
363367
364368 createActionAPIContext ( ) : ActionAPIContext {
365369 const renderContext = this ;
366- const { cookies , params, pipeline, url } = this ;
370+ const { params, pipeline, url } = this ;
367371 const generator = `Astro v${ ASTRO_VERSION } ` ;
368372
369373 const rewrite = async ( reroutePayload : RewritePayload ) => {
370374 return await this . #executeRewrite( reroutePayload ) ;
371375 } ;
372376
373377 return {
374- cookies,
378+ // Don't allow reassignment of cookies because it doesn't work
379+ get cookies ( ) {
380+ return renderContext . cookies ;
381+ } ,
375382 routePattern : this . routeData . route ,
376383 isPrerendered : this . routeData . prerender ,
377384 get clientAddress ( ) {
0 commit comments