Astro Info
Astro v5.13.3
Node v24.4.0
System macOS (arm64)
Package Manager npm
Output server
Adapter @astrojs/node
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Please take a look at the reproducible example in stackblitz.
//middleware.ts
import type { MiddlewareHandler } from 'astro';
import { sequence } from 'astro:middleware';
export const mid1: MiddlewareHandler = async (
{ cookies, locals, rewrite },
next
) => {
console.log('In middleware 1');
cookies.set('cookie1', 'Cookie from middleware 1');
if (!locals.rewritten) {
console.log('Rewriting');
locals.rewritten = true;
return rewrite('/'); // <--- A simple rewrite for demo purposes.
}
return next();
};
export const mid2: MiddlewareHandler = async ({ cookies }, next) => {
console.log('In middleware 2');
cookies.set('cookie2', 'Cookie from middleware 2'); // <--- This cookie never makes it into the Response
return next();
};
export const onRequest: MiddlewareHandler = sequence(mid1, mid2);
When a rewrite happens in one of the middleware layers, any further cookies don't make it into the response. Only the first one.
What's the expected result?
I would expect that cookies set in all middleware layers would get merged into the final Response object.
Note: when not using a rewrite, all cookies make it through. This problem only occurs when a rewrite has happened.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-qv8hj4sw-yc3rx6o8?file=src%2Fmiddleware.ts
Participation
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Please take a look at the reproducible example in stackblitz.
When a rewrite happens in one of the middleware layers, any further cookies don't make it into the response. Only the first one.
What's the expected result?
I would expect that cookies set in all middleware layers would get merged into the final Response object.
Note: when not using a rewrite, all cookies make it through. This problem only occurs when a rewrite has happened.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-qv8hj4sw-yc3rx6o8?file=src%2Fmiddleware.ts
Participation