Next.js Discord

Discord Forum

Identifying Server Actions?

Unanswered
Spectacled bear posted this in #help-forum
Open in Discord
Spectacled bearOP
Hi!

New to server actions...

export async function updateAssemblyNumber({
args,
testId,
}: ServerActionPayload<UpdateAssemblyNumberParams>): Promise<void> {

We're using this testId Param

export interface ServerActionPayload<T> {
testId: string;
args: T;
}

In order to identify which server action response goes with which call.

If we make 3-4 server action calls on a page it can be confusing to see which response goes with wich call...

This has a code smell to me..is there a better way to do this?

6 Replies

Spectacled bearOP
We're currently putting this as part of the request payload so that we can easily distinguish multiple server action calls called from the same page (since they all hit the same URL)
Spectacled bearOP
Again, this just feels like code smell to me, is there a better way to do this for Server Actions?
Or are we not using server actions correctly?
@Spectacled bear Or are we not using server actions correctly?
server action abstract a lot of the network calls internally in next.js. it basically creates an endpoint directly in the same route so you are seeing the network call correctly.

since you're using server action, its most likely you have access to both front-end and back-end. wouldn't it be enough to identify it in the server directly?

im sorry if im misunderstanding the issue, i want to understand the problem clearly.

what do you mean by "In order to identify which server action response goes with which call." ?

wouldn't you be able to right click the server action and see where it is implemented?

thanks in advance
Spectacled bearOP
Thanks for chiming in, this is not about finding the source code. It's about being able to match up which server action response is tied to which call/network payload in the network tab of the dev tools
For instance, if we're calling 4 server actions in succession, it's difficult to know which network call belongs to which server action call given that they're all hitting the same route