Félix
Félix
TTCTheo's Typesafe Cult
Created by Félix on 11/1/2023 in #questions
trpc fetch failed in server actions: Request body length does not match content-length header
Hello guys ! I was trying out the new t3-app boilerplate with the app router and in the example, we have: - Two queries in server side (hello and latest post) - A mutation in client side (create post) I tried to create a mutation in server side like so:
async function createPostAction(formData: FormData) {
"use server";

const postName = formData.get("name")?.toString();

await api.post.create.mutate({ name: postName });
revalidatePath("/");
}
async function createPostAction(formData: FormData) {
"use server";

const postName = formData.get("name")?.toString();

await api.post.create.mutate({ name: postName });
revalidatePath("/");
}
But i have this error message:
RequestContentLengthMismatchError: Request body length does not match content-length header
RequestContentLengthMismatchError: Request body length does not match content-length header
with code
UND_ERR_REQ_CONTENT_LENGTH_MISMATCH
UND_ERR_REQ_CONTENT_LENGTH_MISMATCH
Is trpc mutation supported in server actions or am I doing something impossible ? I suspect it's due to error headers are set for trpc in the server side but i'm not sure...
8 replies