Skip to content

Commit 08c9c8c

Browse files
authored
fix: treat handle hook redirect as part of remote function call as json redirect (#14362)
fixes #14212
1 parent 4d9cc7f commit 08c9c8c

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
@@ -169,11 +169,13 @@ async function handle_remote_call_internal(event, state, options, manifest, id)
169169
);
170170
} catch (error) {
171171
if (error instanceof Redirect) {
172-
return json({
173-
type: 'redirect',
174-
location: error.location,
175-
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
176-
});
172+
return json(
173+
/** @type {RemoteFunctionResponse} */ ({
174+
type: 'redirect',
175+
location: error.location,
176+
refreshes: await serialize_refreshes(form_client_refreshes ?? [])
177+
})
178+
);
177179
}
178180

179181
const status =

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)