withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
43.84k stars 2.28k forks source link

fix(rewrite): correctly update the status code during a rewrite #11352

Open ematipico opened 2 days ago

ematipico commented 2 days ago

Changes

Closes https://github.com/withastro/astro/issues/11306

The issue was caused by this.status inside the RenderContext class. This status code is then passed to the SSResult and used as initial status of Response.

This status code was passed by route.ts. It was a 404 because /foo didn't match any route, however we still call the middleware because the user chose routing: 'manual'.

When we arrived to the middleware, we executed the rewrite, and we need update this status code in case we find a RouteData and a ComponentInstance.

I moved the shared logic inside a new, private, function called #executeRewrite as per @florian-lefebvre suggestion.

Testing

Added a new test case

Docs

N/A

changeset-bot[bot] commented 2 days ago

🦋 Changeset detected

Latest commit: 7af62f72eb90d2aa20ef10923c7ad989b0fb08bd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR