#in next 15, returning response of a fetch call from a server action to a client component errors.

2 messages · Page 1 of 1 (latest)

forest cypress
#

after upgrading next 13 to 15, I encountered an issue, the streamed text doesn't get fully displayed.
I call a server action in useMutation (ReactQuery). in my server action, I used to return the whole response and it used to work correctly, but since I upgraded nextjs, it gave me this error:

[ Server ] 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.
{}
I return an object:

const response = await fetch(
      `${process.env.NEXT_PUBLIC_SUPABASE_URL!}/functions/v1/send-message`,
      {
        method: 'POST',
        headers: {
          Authorization: `Bearer ${accessToken ?? ''}`,
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          content,
        }),
      },
    );

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    return {
      body: response.body,
      status: response.status,
      headers: {
        MSG: response.headers.get('MSG'),
      },
    };
  } catch (error) {
    console.error('sendMessage error: ', error);
    throw error;
  }
};
floral tinselBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)