Skip to content

Conversation

@Bishwas-py
Copy link
Contributor

@Bishwas-py Bishwas-py commented Nov 27, 2025

Fix incorrect invalid import in form API documentation example

Problem

The form API documentation example contained an incorrect import statement that would cause runtime errors for developers following the documentation:

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

This import is incorrect because @sveltejs/kit does not export an invalid function.

Solution

Corrected the form API documentation example to show the proper usage:

  • Removed the incorrect import { invalid } from '@sveltejs/kit' statement
  • Updated the callback signature from async (data, issue) to async (data, invalid)
  • Fixed the usage pattern to invalid(invalid.fieldName(...))

Changes

  import * as v from 'valibot';
- import { invalid } from '@sveltejs/kit';
  import { form } from '$app/server';
  import * as db from '$lib/server/database';

  export const buyHotcakes = form(
    v.object({
      qty: v.pipe(
        v.number(),
        v.minValue(1, 'you must buy at least one hotcake')
      )
    }),
-   async (data, issue) => {
+   async (data, invalid) => {
      try {
        await db.buy(data.qty);
      } catch (e) {
        if (e.code === 'OUT_OF_STOCK') {
-         invalid(
-           issue.qty(`we don't have enough hotcakes`)
-         );
+         invalid(invalid.qty(`we don't have enough hotcakes`));
        }
      }
    }
  );

Impact

This documentation fix will:

  • Prevent confusion for developers implementing form validation
  • Eliminate import errors that would occur when following the previous example
  • Align documentation with the actual form API implementation

#14768 (ref)


Checklist

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

    • Note: This is a straightforward documentation fix for an incorrect import statement
  • This message body should clearly illustrate what problems it solves.

    • Explanation: The incorrect import would cause runtime errors for developers following the documentation
  • Ideally, include a test that fails without this PR but passes with it.

    • Note: Not applicable - this is a documentation-only change with no functional code modifications

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check
    • Status: Will run before final submission

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:.
    • Planned changeset: fix: correct invalid import in form API documentation example (patch level)

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.
    • Confirmed: Maintainer edits are enabled

…mple

Corrected the form API documentation example that incorrectly imported `invalid` from '@sveltejs/kit'. 

The `invalid` function is actually provided as the second parameter to the form callback, not as an export from the kit package. Updated the example to show the correct usage pattern: `async (data, invalid) => { ... }` and properly calling `invalid(invalid.fieldName(...))`.
@changeset-bot
Copy link

changeset-bot bot commented Nov 27, 2025

⚠️ No Changeset found

Latest commit: f1d4ba5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link

Eliminated the redundant return statement in the buyHotcakes function example within the remote functions documentation. This improves clarity and correctness of the example code.
@msfleischer
Copy link

Doesn't the referenced PR #14768 describe how the invalid function must now be imported from @sveltejs/kit? It sounds like the current documentation is correct.

@Bishwas-py
Copy link
Contributor Author

@msfleischer yupp. It might have been a misleading from my side.

@Bishwas-py Bishwas-py closed this Nov 27, 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.

2 participants