Skip to content

Commit

Permalink
[fix] redirects from actions don't honor the provided status code (#8210
Browse files Browse the repository at this point in the history
)

fixes #8209

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
coryvirok and dummdidumm committed Dec 20, 2022
1 parent f2eb25a commit 89b8d94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-pandas-report.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix form action redirect status code
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/index.js
Expand Up @@ -62,7 +62,7 @@ export async function render_page(event, route, page, options, state, resolve_op
// (this also determines status code)
action_result = await handle_action_request(event, leaf_node.server);
if (action_result?.type === 'redirect') {
return redirect_response(303, action_result.location);
return redirect_response(action_result.status, action_result.location);
}
if (action_result?.type === 'error') {
const error = action_result.error;
Expand Down
17 changes: 15 additions & 2 deletions packages/kit/test/apps/basics/test/test.js
Expand Up @@ -2010,12 +2010,25 @@ test.describe('Actions', () => {
);
});

test('redirect', async ({ page }) => {
test('redirect', async ({ page, javaScriptEnabled }) => {
await page.goto('/actions/redirect');

page.click('button');

await Promise.all([page.waitForResponse('/actions/redirect'), page.waitForNavigation()]);
const [redirect] = await Promise.all([
page.waitForResponse('/actions/redirect'),
page.waitForNavigation()
]);
if (javaScriptEnabled) {
expect(await redirect.json()).toEqual({
type: 'redirect',
location: '/actions/enhance',
status: 303
});
} else {
expect(redirect.status()).toBe(303);
expect(redirect.headers()['location']).toBe('/actions/enhance');
}

expect(page.url()).toContain('/actions/enhance');
});
Expand Down

0 comments on commit 89b8d94

Please sign in to comment.