Tinkering with the Conform library with Remix/React Router v7, it was not obvious to me how to return a proper HTTP status code like 422 Unprocessable Content for invalid form data.
This worked:
if (submission.status !== "success") {
return data(submission.reply(), { status: 422 });
}
Took some detours to figure out:
- just returning submission.reply() gives you "200 OK", which is not OK
- json() is deprecated so use data() instead
- trying Zod with data() but without Conform got to a weird place with types