Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shaggy-peas-dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: treat handle hook redirect as part of remote function call as json redirect
12 changes: 7 additions & 5 deletions packages/kit/src/runtime/server/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ async function handle_remote_call_internal(event, state, options, manifest, id)
);
} catch (error) {
if (error instanceof Redirect) {
return json({
type: 'redirect',
location: error.location,
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
});
return json(
/** @type {RemoteFunctionResponse} */ ({
type: 'redirect',
location: error.location,
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
})
);
}

return json(
Expand Down
11 changes: 6 additions & 5 deletions packages/kit/src/runtime/server/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,12 @@ export async function internal_respond(request, options, manifest, state) {
return response;
} catch (e) {
if (e instanceof Redirect) {
const response = is_data_request
? redirect_json_response(e)
: route?.page && is_action_json_request(event)
? action_json_redirect(e)
: redirect_response(e.status, e.location);
const response =
is_data_request || remote_id
? redirect_json_response(e)
: route?.page && is_action_json_request(event)
? action_json_redirect(e)
: redirect_response(e.status, e.location);
add_cookies_to_headers(response.headers, new_cookies.values());
return response;
}
Expand Down
Loading