Skip to content

Commit 89b8d94

Browse files
[fix] redirects from actions don't honor the provided status code (#8210)
fixes #8209 Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
1 parent f2eb25a commit 89b8d94

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

.changeset/tidy-pandas-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Fix form action redirect status code

packages/kit/src/runtime/server/page/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function render_page(event, route, page, options, state, resolve_op
6262
// (this also determines status code)
6363
action_result = await handle_action_request(event, leaf_node.server);
6464
if (action_result?.type === 'redirect') {
65-
return redirect_response(303, action_result.location);
65+
return redirect_response(action_result.status, action_result.location);
6666
}
6767
if (action_result?.type === 'error') {
6868
const error = action_result.error;

packages/kit/test/apps/basics/test/test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,12 +2010,25 @@ test.describe('Actions', () => {
20102010
);
20112011
});
20122012

2013-
test('redirect', async ({ page }) => {
2013+
test('redirect', async ({ page, javaScriptEnabled }) => {
20142014
await page.goto('/actions/redirect');
20152015

20162016
page.click('button');
20172017

2018-
await Promise.all([page.waitForResponse('/actions/redirect'), page.waitForNavigation()]);
2018+
const [redirect] = await Promise.all([
2019+
page.waitForResponse('/actions/redirect'),
2020+
page.waitForNavigation()
2021+
]);
2022+
if (javaScriptEnabled) {
2023+
expect(await redirect.json()).toEqual({
2024+
type: 'redirect',
2025+
location: '/actions/enhance',
2026+
status: 303
2027+
});
2028+
} else {
2029+
expect(redirect.status()).toBe(303);
2030+
expect(redirect.headers()['location']).toBe('/actions/enhance');
2031+
}
20192032

20202033
expect(page.url()).toContain('/actions/enhance');
20212034
});

0 commit comments

Comments
 (0)