Passing callback to server action
Unanswered
Barbary Lion posted this in #help-forum
Barbary LionOP
How to pass callback from client component to server action?
I have long running task that runs inside server action and would like to get progress updates and update UI. But when I passed callback to server component I got an error
I have long running task that runs inside server action and would like to get progress updates and update UI. But when I passed callback to server component I got an error
15 Replies
server actions are just api routes... they can communicate like that between each other
but do you mean progress like (1%... 50%) and such
as to make a progress indicator simply, you should just make a route (can be server action), and make another one which you just request every so often until it is finished
you could also use streaming to display live progress: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#streaming (second code block)
Barbary LionOP
ok, I see
I know it's just api routes, but it's wrapped with some more functionality so imo having working callback would be nice
yeah thats why i think this ^ may be helpful for you
idk if server actions can do that
im just trying to think on how chaotic it would be to actually implement (with all the edge cases)
Barbary LionOP
Before that I used Comlink and ran the action inside service worker so all the callback had to be serialized as well, so I think it could work simiarly
Let's see what they show on the next conf soon
and because they are still in beta, anything is possible
so, what are you going to do in the mean time?
Barbary LionOP
Just won't use onProgress for now
so ig you can close this thread as it won't be solved for a while, if ever ;(