#Do I need a transition to call a server action in "onSubmit"?

10 messages · Page 1 of 1 (latest)

pastel thunder
#

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?

dreamy geodeBOT
#

🔎 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)

pastel thunder
#

Small bump

hollow spire
pastel thunder
#

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?

hollow spire
#
  • 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 startTransition used to be documented in the nextjs documentation, but removed in this commit.
hollow spire
young glade
#

does the title have to be so large and scary sweating