Open2

Next.jsのUncaught (in promise) Error: Only plain objects...エラーの対処

dallPdallP

Uncaught (in promise) Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.

スタックトレースがまともに出ないので、どこがヤラカシているのかが非常に分かりにくい。
が、基本的にサーバー(コンポーネント)とクライアントコンポーネントの境界で発生する。

dallPdallP

自分の場合はサーバーコンポーネント「ではなく」、Server Action(サーバーアクション)とクライアントコンポーネントの境界で起きた問題だった。

エラーメッセージが罠すぎる。

具体的にはServer Actionから、うっかりClassのインスタンスを返却していたのが問題だった。

上記メッセージの通り、サーバーコンポーネントからクライアントコンポーネントへの受け渡しデータは(少なくとも現状は)プレーンオブジェクトである必要がある。

これは、クライアントコンポーネントから呼び出したServer Actionの返り値でも同じ扱いの模様。

数時間溶かしました。