RequestContentLengthMismathError, Form Actions Redirect
Unanswered
Snowshoe posted this in #help-forum
SnowshoeOP
When using form actions with calling redirect, i get RequestContentLengthMismatchError
Code Example:
Exception:
Code Example:
import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
export const FormComponent = (props: FormComponentProps) => {
const { aProp } = props;
const formSubmit = async (form: FormData) => {
"use server";
// do stuff
revalidatePath("/admin/users/[id]");
revalidatePath("/admin/users/[id]/deviceadd"); // this page
redirect(`/admin/users/${user.id}`);
};
return (
<form action={formSubmit}>
</form>
);
}Exception:
failed to get redirect response TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at write (/project/node_modules/next/dist/compiled/undici/index.js:1:67105)
at _resume (/project/node_modules/next/dist/compiled/undici/index.js:1:66726)
at resume (/project/node_modules/next/dist/compiled/undici/index.js:1:65413)
at connect (/project/node_modules/next/dist/compiled/undici/index.js:1:65301) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}1 Reply
SnowshoeOP
Request Headers:
Request Body:
Response Headers:
Response Body:
POST /admin/users/52/deviceadd HTTP/1.1
Host: localhost:3000
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/x-component
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: http://localhost:3000/admin/users/52/deviceadd
Next-Action: 5112fa3e1bd9b815c85667e06018532a97aa16e6
Next-Router-State-Tree: ["",{"children":["admin",{"children":["users",{"children":[["id","52","d"],{"children":["deviceadd",{"children":["__PAGE__",{}]}]}]}]}]},null,null,true]
Next-Url: /admin/users/52/deviceadd
Content-Type: multipart/form-data; boundary=---------------------------11103585335007450491473979489
Content-Length: 560
Origin: http://localhost:3000
Connection: keep-alive
Cookie: Secret
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-originRequest Body:
-----------------------------11103585335007450491473979489
Content-Disposition: form-data; name="1_action"
submit
-----------------------------11103585335007450491473979489
Content-Disposition: form-data; name="1_email"
thaun1@live.no
-----------------------------11103585335007450491473979489
Content-Disposition: form-data; name="1_device_id"
0H0FLLQm1cdCAuToIJ2o9
-----------------------------11103585335007450491473979489
Content-Disposition: form-data; name="0"
[52,"$K1"]
-----------------------------11103585335007450491473979489--Response Headers:
HTTP/1.1 200 OK
date: Tue, 11 Jul 2023 07:53:34 GMT
vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Accept-Encoding
x-action-revalidated: [[],1,0]
x-action-redirect: /admin/users/52
cache-control: no-store, must-revalidate
x-powered-by: Next.js
etag: "bwc9mymkdm2"
content-type: text/html; charset=utf-8
content-length: 2
keep-alive: timeout=5
connection: closeResponse Body:
{}