Skip to content

chore: dedupe the form action request handlers - #16835

Open
Nic-Polumeyv wants to merge 7 commits into
version-3from
chore-action-error-result
Open

chore: dedupe the form action request handlers#16835
Nic-Polumeyv wants to merge 7 commits into
version-3from
chore-action-error-result

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

handle_action_json_request in runtime/server/page/actions.js was a copy of handle_action_request that differed only in how each branch was encoded, and the 405 result was written out a third time in handle_remote_form_post_internal (runtime/server/remote-functions.js). #16684 had to add location to every copy. handle_action_request now runs once and action_result_json encodes the result for the JSON transport; method_not_allowed_result and action_error_result are shared with the remote form POST handler.

The fail() misuse check is no longer in the shared catch, since fail() is form-action only. Remote form handlers get a dev-time error for a thrown or returned fail() in app/server/remote/form.js, covering both the enhanced and no-JS transports.

ServerActionResult (types/internal.d.ts) types the pre-handleError result, so we're no longer lying about the types.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 17, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from bd58141:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/bd5814179d8ab706ec1a0c9b8d187ffb7429f71e

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16835

@changeset-bot

changeset-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bd58141

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@svelte-docs-bot

Copy link
Copy Markdown

@Rich-Harris

Copy link
Copy Markdown
Member

I think the existing behaviour might be slightly wrong here. fail(...) is specific to form actions; a form remote function handler should either return a value (or void) or throw a ValidationError via invalid(...). It shouldn't throw or return fail(...). So I think we probably want to pull that bit out of action_error_result and add some dev-time logic to handle_remote_form_post_internal to handle incorrect fail usage

@Nic-Polumeyv
Nic-Polumeyv marked this pull request as draft August 18, 2026 15:51
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.
@Nic-Polumeyv Nic-Polumeyv changed the title chore: share the action error result between form actions and remote forms chore: dedupe the form action request handlers Aug 19, 2026
@Nic-Polumeyv
Nic-Polumeyv marked this pull request as ready for review August 19, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants