Skip to content

feat: return boolean from submit to indicate submission validity#15530

Merged
Rich-Harris merged 7 commits into
mainfrom
submit-returns-boolean
Apr 5, 2026
Merged

feat: return boolean from submit to indicate submission validity#15530
Rich-Harris merged 7 commits into
mainfrom
submit-returns-boolean

Conversation

@Rich-Harris

Copy link
Copy Markdown
Member

With this PR, a submit in an enhanced remote form returns a boolean indicating whether it was valid or not:

try {
  if (await submit()) {
    // success (return or redirect)
  } else {
    // validation error
  }
} catch (e) {
  // something went wrong
}

The alternative approach we considered was to throw an error on invalid data. But that feels more cumbersome, since now you need to differentiate between different error types:

import { isHttpError } from '@sveltejs/kit';

// later
try {
  await submit();
  // success (return or redirect)
} catch (e) {
  if (isHttpError(e, 400)) {
    // validation error
  } else {
    // something went wrong
  }
}

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot

changeset-bot Bot commented Mar 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 516ea3a

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 Minor

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 Author

/autofix

@teemingc teemingc added the forms Stuff relating to forms and form actions label Mar 10, 2026
Comment thread .changeset/twelve-taxis-move.md Outdated
@teemingc

Copy link
Copy Markdown
Member

Do we want to consider returning the submitted data instead of a boolean? #14082

@Rich-Harris Rich-Harris merged commit 3290a0c into main Apr 5, 2026
28 checks passed
@Rich-Harris Rich-Harris deleted the submit-returns-boolean branch April 5, 2026 17:14
This was referenced Apr 5, 2026
elliott-with-the-longest-name-on-github pushed a commit that referenced this pull request Apr 20, 2026
closes #15700

The enhance function can be (and usually is) async. The return type must
therefore not be `void` but `void | Promise<void>` to prevent triggering
[`@typescript-eslint/no-misused-promises`](https://typescript-eslint.io/rules/no-misused-promises/)

The return type was changed from `void | Promise<void>` to `void` in
#15530, which I think was a regression. This PR changes it back.

---

### Please don't delete this checklist! Before submitting the PR, please
make sure you do the following:
- [x] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it
solves.
- [ ] Ideally, include a test that fails without this PR but passes with
it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more
packages' changelogs, generate a changeset by running `pnpm changeset`
and following the prompts. Changesets that add features should be
`minor` and those that fix bugs should be `patch`. Please prefix
changeset messages with `feat:`, `fix:`, or `chore:`.

### Edits

- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forms Stuff relating to forms and form actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants