Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] redirects from actions don't honor the provided status code #8210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-pandas-report.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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