I have a page where I want to ge the initial value during static rendering, and then relay with SWR client-side to do polling for new values without refresh
The user can increment the value
User can increment the value, when this happens I need to invalidate SWR locally => this means calling "mutate()" after the server action is done => this means I can't write action={incrementCounter}, I have to use onSubmit
The doc mentions using "transitions" when calling Server Actions outside of "action", is that mandatory? Can I write onSubmit={async (evt) => { await incrementCounter(evt.formData); mutate("/api/counter")} } or should I also involve transitions here?
#Do I need a transition to call a server action in "onSubmit"?
10 messages · Page 1 of 1 (latest)
🔎 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)
Small bump
The transition is recommended because it marks the action trigger as a react transition, same way react transition is recommended for router methods.
But it is not required. As far as I know, "use server" marks exported async functions as server-side functions callable by the client, so you can use it like normal client-side async functions without having to wrap it inside transition APIs
What I don't get is that transitions seems needed for slow blocking operations like rendering
while normally an async call should not block
so perphaps it brings the possibility of cancelling the call?
- so i found this very interesting note: transitions must be synchronous. meanwhile server actions must be asynchronous. i'm struggling to even cleanly combine the two in a way that TS is happy.
- using server actions without
startTransitionused to be documented in the nextjs documentation, but removed in this commit.
i opened this https://github.com/vercel/next.js/issues/57652 because it no longer makes sense to me anymore
does the title have to be so large and scary 