chore: dedupe the form action request handlers - #16835
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/bd5814179d8ab706ec1a0c9b8d187ffb7429f71eOpen in |
🦋 Changeset detectedLatest commit: bd58141 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I think the existing behaviour might be slightly wrong here. |
fail() is form-action only; a remote form handler returns a value or throws invalid(). Guard against both thrown and returned fail() in the form handler itself so both transports report it.
handle_action_json_request duplicated handle_action_request except for the output shape. Run the shared path once and encode the ActionResult, and share the 405 result with the remote form POST handler.
The error is passed through handleError and the data serialized later, so neither is what ActionResult says it is until action_result_json runs.
handle_action_json_requestinruntime/server/page/actions.jswas a copy ofhandle_action_requestthat differed only in how each branch was encoded, and the 405 result was written out a third time inhandle_remote_form_post_internal(runtime/server/remote-functions.js). #16684 had to addlocationto every copy.handle_action_requestnow runs once andaction_result_jsonencodes the result for the JSON transport;method_not_allowed_resultandaction_error_resultare shared with the remote form POST handler.The
fail()misuse check is no longer in the shared catch, sincefail()is form-action only. Remoteformhandlers get a dev-time error for a thrown or returnedfail()inapp/server/remote/form.js, covering both the enhanced and no-JS transports.ServerActionResult(types/internal.d.ts) types the pre-handleErrorresult, so we're no longer lying about the types.