-
-
Notifications
You must be signed in to change notification settings - Fork 100
Open
Labels
bugSomething isn't workingSomething isn't working
Description
- Before posting an issue, read the FAQ and search the previous issues.
Description
When updating the zod library in the official example in https://github.com/ciscoheat/superforms-examples/tree/zod to any version >= 4.0.0 (tested right now with 4.1.5), the error messages are always "Invalid Input" when starting the application with pnpm dev
.
Setting the locale explicitly with
import z from 'zod';
z.config(z.locales.de());
does not change this behaviour.
To see that this locale configuration has the correct effect, you can add
console.log(z.prettifyError(schema.safeParse({ name: '', email: '' }).error!));
at the start of the action.
Full +page.server.ts
:
import { fail, message, superValidate } from 'sveltekit-superforms';
import { zod4 } from 'sveltekit-superforms/adapters';
import z from 'zod';
import { schema } from './schema.js';
z.config(z.locales.de());
export const load = async () => {
return { form: await superValidate(zod4(schema)) };
};
export const actions = {
default: async ({ request }) => {
console.log(z.prettifyError(schema.safeParse({ name: '', email: '' }).error!));
const form = await superValidate(request, zod4(schema));
console.log(form);
if (!form.valid) return fail(400, { form });
return message(form, 'Form posted successfully!');
}
};
This logs the following when submitting with empty form fields:
✖ Zu klein: erwartet, dass string >=2 Zeichen hat
→ at name
✖ Ungültig: E-Mail-Adresse
→ at email
{
id: '9yawuu',
valid: false,
posted: true,
errors: { name: [ 'Invalid input' ], email: [ 'Invalid input' ] },
data: { name: '', email: '' }
}
What is kind of confusing to me is the fact, that this behaviour only appears when running pnpm dev
. When served by pnpm build && pnpm preview
, the logs (and also the frontend) show the correct messages:
✖ Zu klein: erwartet, dass string >=2 Zeichen hat
→ at name
✖ Ungültig: E-Mail-Adresse
→ at email
{
id: '9yawuu',
valid: false,
posted: true,
errors: {
name: [ 'Zu klein: erwartet, dass string >=2 Zeichen hat' ],
email: [ 'Ungültig: E-Mail-Adresse' ]
},
data: { name: '', email: '' }
}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working