Skip to content

Conversation

@dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Oct 20, 2025

How to migrate

Instead of throwing with the passed in parameter, you now throw via the imported invalid function from @sveltejs/kit.

+ import { invalid } from '@sveltejs/kit';
import { form } from '$app/server';

export const myForm = form(
  someSchema,
-  (data, invalid) => {
+  (data, issue) => {
    invalid(
      'something went wrong',
-     invalid.some.field('message')
+     issue.some.field('message')
    );
  }
);

PR description

TypeScript kinda forced our hand here - due to limitations of control flow analysis it does not detect the never return type for anything else than functions that are used directly (i.e. passing a function as a parameter doesn't work unless you explicitly type it); see microsoft/TypeScript#36753 for more info.

This therefore changes invalid to be a function that you import just like redirect or error. A nice benefit of this is that you'll no longer have to use the second parameter passed to remote form functions to construct the list of issues in case you want to create an issue for the whole form and not just a specific field.

Closes #14745


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:.

TypeScript kinda forced our hand here - due to limitations of control flow analysis it does not detect the `never` return type for anything else than functions that are used directly (i.e. passing a function as a parameter doesn't work unless you explicitly type it); see microsoft/TypeScript#36753 for more info.

This therefore changes `invalid` to be a function that you import just like `redirect` or `error`. A nice benefit of this is that you'll no longer have to use the second parameter passed to remote form functions to construct the list of issues in case you want to create an issue for the whole form and not just a specific field.

Closes #14745
@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2025

🦋 Changeset detected

Latest commit: 73cbfa3

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

@Rich-Harris Rich-Harris merged commit bd55128 into main Nov 20, 2025
25 checks passed
@Rich-Harris Rich-Harris deleted the invalid-exported branch November 20, 2025 21:31
@github-actions github-actions bot mentioned this pull request Nov 20, 2025
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.

Docs: Imperative invalidation caveat

3 participants