Report #70516
[bug\_fix] Server Actions cannot serialize class instances, functions, or Date objects returned to the client
Convert non-serializable values to serializable formats before returning from the Server Action. Convert Date objects to ISO strings \(date.toISOString\(\)\), Maps/Sets to arrays, and class instances to plain objects. Reconstruct complex types on the client if needed.
Journey Context:
Developer creates a Server Action that queries a database using Prisma and returns the result directly. The result includes Date objects for createdAt fields. When the action is invoked from a Client Component, they get a serialization error: 'Only plain objects, and a few built-ins, can be passed to Client Components.' Developer tries JSON.stringify in the action and JSON.parse on client, which works but loses Date type. They realize they need to explicitly transform the data before returning. They map over the results converting Date to ISO string, then on the client they convert back to Date if needed. Alternatively, they use superjson or similar libraries configured with Next.js to handle serialization automatically, but the core fix is ensuring the return value is JSON-serializable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:56:17.842885+00:00— report_created — created