Next.js Discord

Discord Forum

Debugging “Only …. can be passed to Client components from Server components”

Answered
Pacific herring posted this in #help-forum
Open in Discord
Pacific herringOP
Hey,

I am getting the error that you can see in the title, but I have no idea where I am passing “invalid” data from and to. The stack trace is no help.

How do I proceed?
Answered by Pacific herring
The fix was this essentially:
View full answer

35 Replies

Cimarrón Uruguayo
you've provided no information on how we can help you proceed
Pacific herringOP
That’s my problem as well :/
The stack trace just shows next.js framework-specific files
I don’t know where the error is coming from
Cimarrón Uruguayo
see if the following links are relevant
that's all i can help u
Pacific herringOP
I'll try and collect the code that (I think) has the bug, give me a second and thanks for taking the time
I have a page.tsx server component, which prefetches data via react query and hydrates it like in the Tanstack query docs:
Where the function passed to queryFn, getPartners is a server function
And the argument passed to getPartners is serializeable (just a plain old object containing two numbers, {pageNumber, pageSize})
The issue arises when I try to delete/edit an entity
@Pacific herring I have a `page.tsx` server component, which prefetches data via react query and hydrates it like in the Tanstack query docs:
Pacific herringOP
From here, the path to the delete call is as follows:

- AllPartners (client component, which uses the prefetched data)
- DataTable (client component, this is straight from shadcn/ui)
- The delete action is accessible via a dropdown menu in the table, which is defined in a separate columns.tsx file (also a client component)
- The mutation UI/action is also in a separate file, delete-partner.tsx (client component)
Here, the mutation function, deletePartner is a server function
When I delete an entity, I get the error I said in the title
But the entity itself gets deleted and when I reload the page, it is gone
So it seems to be that the action is successful, but I get an error anyways?
The error says that I am passing "non-serializeable" data from a server component to a client component
But the only direct server-client component relation in this tree is page.tsx-AllPartners, where only the id (number) property is passed
That's why I'm a bit baffled by this error and having a hard time tracking it down
@Pacific herring Click to see attachment
Pacific herringOP
I should add, that the functions that are called in onSuccess are both in a file marked use client
@Pacific herring Click to see attachment
Pacific herringOP
I have traced it down to the mutationFn call
Once I click on the button which calls mutate() I get the error
Okay I got it...
I am big dumb
The deletePartner server function was returning the Promise back to the client
Pacific herringOP
The fix was this essentially:
Answer
Cimarrón Uruguayo
all you bro
good job
Pacific herringOP
Is there an issue in the NextJS for having better stack traces for issues like this?
It would've been nice to know that the non-serializeable data was coming from deletePartner