Skip to content

Commit ff10c4a

Browse files
committed
fix: treat handle hook redirect as part of remote function call as json redirect
fixes #14212
1 parent 7044ea7 commit ff10c4a

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

.changeset/shaggy-peas-dig.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: treat handle hook redirect as part of remote function call as json redirect

packages/kit/src/runtime/server/remote.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ async function handle_remote_call_internal(event, state, options, manifest, id)
124124
);
125125
} catch (error) {
126126
if (error instanceof Redirect) {
127-
return json({
128-
type: 'redirect',
129-
location: error.location,
130-
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
131-
});
127+
return json(
128+
/** @type {RemoteFunctionResponse} */ ({
129+
type: 'redirect',
130+
location: error.location,
131+
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
132+
})
133+
);
132134
}
133135

134136
return json(

packages/kit/src/runtime/server/respond.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,12 @@ export async function internal_respond(request, options, manifest, state) {
505505
return response;
506506
} catch (e) {
507507
if (e instanceof Redirect) {
508-
const response = is_data_request
509-
? redirect_json_response(e)
510-
: route?.page && is_action_json_request(event)
511-
? action_json_redirect(e)
512-
: redirect_response(e.status, e.location);
508+
const response =
509+
is_data_request || remote_id
510+
? redirect_json_response(e)
511+
: route?.page && is_action_json_request(event)
512+
? action_json_redirect(e)
513+
: redirect_response(e.status, e.location);
513514
add_cookies_to_headers(response.headers, new_cookies.values());
514515
return response;
515516
}

0 commit comments

Comments
 (0)