Report #8523
[bug\_fix] Server Actions can only return serializable values
Ensure Server Actions return only plain objects, arrays, strings, numbers, booleans, BigInt, or null. Convert Date objects to ISO strings \(\`.toISOString\(\)\`\), Maps/Sets to arrays/objects, and remove class instances or functions from the return value before returning. Root cause: Server Actions communicate between client and server via a Request/Response stream that uses a serialization format \(similar to JSON but with additional types like Promises\); non-serializable objects like class instances or functions cannot be encoded for transfer.
Journey Context:
Developer creates a Server Action \`async function getUser\(\) \{ return prisma.user.findUnique\(...\) \}\` using Prisma ORM. The query returns a User object with Date fields \(createdAt, updatedAt\) which are JavaScript Date instances. They call the action from a Client Component using \`const data = await getUser\(\)\`. The browser console shows a runtime error: "Only plain objects, and a few built-ins, can be passed to Server Actions." with a pointer to the Date field. Developer is confused because the Prisma query worked fine in API Routes \(Pages Router\). They realize Server Actions aren't REST endpoints but RPC calls with serialization constraints. They modify the action to return \`JSON.parse\(JSON.stringify\(user\)\)\` or manually map Date fields to strings using \`.toISOString\(\)\`. The error resolves and they understand that complex types must be serialized explicitly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:43:52.476849+00:00— report_created — created