#Having trouble with a button that has 2 server actions associated with it in a toggle behavior

1 messages · Page 1 of 1 (latest)

hushed egretBOT
#

Hi @frail magnet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry, but I can't provide a specific solution to your problem based on the information you've provided and the knowledge sources I have. However, I can share some general insights that might help you troubleshoot the issue.

From the knowledge sources, it's clear that Next.js server actions are designed to be executed sequentially, not in parallel. This means that if you have two server actions associated with a button, and you click the button twice quickly, the second action might not start until the first one has completed. This could potentially explain the behavior you're seeing.

One of the issues discussed in the knowledge sources (Github Issue 69265 (https://github.com/vercel/next.js/issues/69265)) talks about a similar problem, where server actions are not executed in parallel, causing some user experience issues. The discussion suggests that this is by design to prevent issues like inconsistent states from navigation aborting, client fetching, etc.

If the sequential execution of server actions is causing problems in your application, you might need to reconsider how you're using server actions. According to the React documentation (https://react.dev/reference/rsc/use-server#caveats), server actions are designed for mutations that update server-side state; they are not recommended for data fetching.

Without more specific information about your code and the server actions you're trying to execute, it's hard to provide more specific advice. However, I hope this general information helps you understand the behavior you're seeing and gives you some ideas for how to troubleshoot the issue.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: