sveltekit-superforms
sveltekit-superforms copied to clipboard
[Vercel Edge]: Form data is empty if `superValidate` is passed a `FormData` object.
This is a very weird bug, but it bit me in production really hard.
In a server action, I noticed that if I extract the FormData from the request and pass the result to superValidate, the returned form has no data, even though the data is actually in the FormData object. I realized this when the forms where I do this started to return validation errors for correct data.
const schema = z.object({
name: z.string().min(1),
email: z.string().email(),
message: z.string().min(1)
});
const formData = await request.formData();
const form = await superValidate(formData, zod(schema));
// form: { data: { name: '', email: '', message: '' } }
I couldn't make a reproduction for this in Sveltelab, so I made a barebones repo https://github.com/ciscoheat/sveltekit-superforms/issues.
The deployment is here: https://vercel-edge-superforms.vercel.app/
If you submit valid data in the form, you'll see that errors are shown nonetheless. You can verify that the errors are coming from the server by looking at the network tab. There is also purposefully no client-side validation.
I briefly tried the serverless runtime in the repro and the bug went away, so it only seems to happen in Vercel's edge runtime. I haven't tried other platforms.