Fix saveLesson: sanitize content JSON to prevent RSC proxy error

React treats TipTap's editor.getJSON() output as a non-plain object when
passed through Server Action serialization, causing isDecimal() inside
Prisma's query builder to receive a temporary client reference proxy and
throw ERROR 1213974697. JSON.parse(JSON.stringify()) strips the prototype
chain and any non-enumerable properties, ensuring Prisma receives a
clean plain object.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 17:58:13 +05:00
parent 8757537344
commit bfa037885f
+9 -14
View File
@@ -22,20 +22,15 @@ export async function saveLesson(
}
) {
await requireAdmin();
try {
await prisma.lesson.update({
where: { id: lessonId },
data: {
title: data.title,
kinescopeId: data.kinescopeId || null,
content: JSON.parse(JSON.stringify(data.content)),
published: data.published,
},
});
} catch (err) {
console.error("[saveLesson] full error:", err);
throw err;
}
await prisma.lesson.update({
where: { id: lessonId },
data: {
title: data.title,
kinescopeId: data.kinescopeId || null,
content: JSON.parse(JSON.stringify(data.content)),
published: data.published,
},
});
revalidatePath(`/admin/courses/${courseId}/modules/${moduleId}`);
revalidatePath(`/admin/courses/${courseId}/modules/${moduleId}/lessons/${lessonId}`);
}