Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Content-Type: application/json

Set `cron` to an expression exported by your job. A successful call returns `{ "ok": true }`.

The endpoint requires a local dev trigger token. Void prints a paste-ready curl command with the current token when the dev server starts.
The endpoint requires a local dev trigger token. Void prints a paste-ready curl command with the current token when the dev server starts. The development trigger is unavailable in `vp preview` and `vite preview`.

```bash
curl -X POST http://localhost:5173/__void/scheduled \
Expand Down
51 changes: 36 additions & 15 deletions docs/guide/pages-routing/actions-and-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Middleware does not run again after the action. To change [shared data](./layout

## Form

Pair `Form` with `useForm` to submit values and display validation and action errors. Inputs stay editable when a submission fails.
Pair `Form` with `useForm` to submit values. Inputs stay editable when a submission fails. `Form` shows an alert above the fields when there is an error. The alert shows the action error from `form.error` when present and joins the messages from `form.errors` otherwise.

Import `Form` from your adapter. Pass `form` and, optionally, `method="put"`, `"patch"`, or `"delete"`; the default is `"post"`. Use `renderError` for a custom action-error renderer (a snippet in Svelte).
Import `Form` from your adapter. Pass `form` and optionally set `method` to `"put"`, `"patch"`, or `"delete"`. The default is `"post"`. Use `renderError` for custom action-error text (a snippet in Svelte). Field messages use the alert with or without `renderError`.

## `useForm`

Expand Down Expand Up @@ -66,14 +66,12 @@ export default function CreateUser() {
value={form.data.name}
onChange={(e) => form.setData('name', e.target.value)}
/>
{form.errors.name && <span>{form.errors.name}</span>}

<input
name="email"
value={form.data.email}
onChange={(e) => form.setData('email', e.target.value)}
/>
{form.errors.email && <span>{form.errors.email}</span>}

<SubmitButton />
</Form>
Expand All @@ -92,10 +90,7 @@ const form = useForm('/users', { name: '', email: '' });
<template>
<Form :form="form">
<input v-model="form.data.name" />
<span v-if="form.errors.name">{{ form.errors.name }}</span>

<input v-model="form.data.email" />
<span v-if="form.errors.email">{{ form.errors.email }}</span>

<button :disabled="form.pending">Create</button>
</Form>
Expand All @@ -112,10 +107,7 @@ const form = useForm('/users', { name: '', email: '' });

<Form {form}>
<input bind:value={form.data.name} />
{#if form.errors.name}<span>{form.errors.name}</span>{/if}

<input bind:value={form.data.email} />
{#if form.errors.email}<span>{form.errors.email}</span>{/if}

<button disabled={form.pending}>Create</button>
</Form>
Expand All @@ -131,10 +123,7 @@ export default function CreateUser() {
return (
<Form form={form}>
<input value={form.data.name} onInput={(e) => form.setData('name', e.target.value)} />
{form.errors.name && <span>{form.errors.name}</span>}

<input value={form.data.email} onInput={(e) => form.setData('email', e.target.value)} />
{form.errors.email && <span>{form.errors.email}</span>}

<button disabled={form.pending}>Create</button>
</Form>
Expand Down Expand Up @@ -333,9 +322,41 @@ import { useForm } from '@void/react'; // or "@void/vue", "@void/svelte", "@void
const form = useForm('/users', { name: '', email: '' }, { throwOnError: false });
```

Validation errors appear in `form.errors`; other HTTP failures appear in `form.error`. `Form` displays the error for you. In React, `onError` also receives it.
Validation errors appear in `form.errors`. Other HTTP failures appear in `form.error`. In React, `onError` also receives the error.

Network errors and other unexpected failures still throw. Cancelled submissions don't set `form.error`.

When the alert shows field errors, rendering `form.errors.<field>` inside `Form` repeats the message. To show each message beside its input, use a plain `<form>` that submits with `form.post`. A plain form can submit during a retry delay unless you block submission yourself.

In React, pass `form.post` as the form's action.

```tsx
import { useForm } from '@void/react';

export default function CreateUser() {
const form = useForm('/users', { name: '', email: '' });

return (
<form action={form.post}>
<input
name="name"
value={form.data.name}
onChange={(e) => form.setData('name', e.target.value)}
/>
{form.errors.name && <span>{form.errors.name}</span>}

<input
name="email"
value={form.data.email}
onChange={(e) => form.setData('email', e.target.value)}
/>
{form.errors.email && <span>{form.errors.email}</span>}

Network errors and other unexpected failures still throw. Cancelled submissions don't set a form error.
<button disabled={form.pending}>Create</button>
</form>
);
}
```

Use `isVoidActionError()` to read an action error's `status` and `message`, including thrown errors:

Expand Down
4 changes: 3 additions & 1 deletion docs/guide/pages-routing/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Action errors that reach a client boundary keep their HTTP status and public mes

## HTTP exceptions

Throw an `HTTPException` to show a specific error in your page's layout. For example, a suspended account can return `403` with an explanation:
Throw an `HTTPException` to show a specific error. Void renders the selected `_error` inside the page's layouts at or above the error component's directory, including any named layout at those positions. Deeper layouts are dropped. With `layout = false`, the error renders on its own. To keep a section's navigation, [add an `_error` in that section](#nested-errors).

A suspended account can return `403` with an explanation.

```ts
// pages/account.server.ts
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Content-Type: application/json
{ "queue": "<queue-name>", "messages": [{ "id": "1", "timestamp": <unix_ms>, "body": <any>, "attempts": 1 }] }
```

The endpoint requires a local dev trigger token. Void prints a paste-ready curl command with the current token when the dev server starts.
The endpoint requires a local dev trigger token. Void prints a paste-ready curl command with the current token when the dev server starts. The development trigger is unavailable in `vp preview` and `vite preview`.

```bash
curl -X POST http://localhost:5173/__void/queue \
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/frameworks/sveltekit.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cd my-app
### 2. Install dependencies

```bash
npm install -D @sveltejs/adapter-cloudflare void
npm install -D @sveltejs/adapter-cloudflare@8 void
```

### 3. Configure `vite.config.ts`
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/cli/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ If a statement fails, stdout stays empty.
void db migrate [--remote]
```

Apply pending migrations to the local database without resetting. Unlike `void db reset`, this preserves existing data and only runs migrations that haven't been applied yet.
Apply pending migrations to the local database without resetting. Unlike `void db reset`, this preserves existing data and only runs migrations that haven't been applied yet. To allow a destructive migration, add `-- void:allow-destructive` on its own line in the SQL file.

Pass `--remote` to apply pending migrations to the saved target. Hosted projects require a Void login and link. Direct Cloudflare D1 projects use the binding's configured migration directory, table, and pattern. The D1 binding must set `migrations_dir`. Direct PostgreSQL and MySQL projects use the shell `DATABASE_URL`.

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void init --toolchain vite-plus --framework react --starter sqlite --deploy none
npm create void@latest my-app -- --toolchain vite-plus --framework react --starter sqlite --deploy none
```

`npm create void <name>` takes a single directory name and creates it inside the current directory. Use up to 63 characters from `a-z`, `0-9`, and `-`, with a letter or digit at each end.

For non-interactive scaffolding, choose `--deploy none` and run `void connect` later to sign in.

Vite+ is the recommended toolchain. Vite+ starters include [`@cloudflare/oxlint-config`](https://github.com/cloudflare/oxlint-config). Run `vp lint` to check your code.
Expand Down