server action returns a prisma row and next throws "only plain objects can be passed" Serialization
Next 15.4, app router. The action is four lines:
'use server'
export async function getInvoice(id: string) {
return prisma.invoice.findUnique({ where: { id } })
}
A client component calls it inside a transition and I get Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported. It names the total field. If I log the object on the server it looks completely ordinary. What is it actually objecting to?
@layer_shift_lu · 4h ago
Write the mapper by hand and stop treating actions as "return the row". I keep a
toInvoiceDTO(row)next to the action and a zod schema for the return type. The schema costs ten lines and gives you an actual contract — when someone adds a column with a weird type the parse fails in a test, not as a runtime warning in a browser someone else is using.Reply
Report