TheSGJ / nextjs-toploader

A Next.js Top Loading Bar component made using nprogress, works with Next.js 14 , Next.js 13 and React.
https://www.npmjs.com/package/nextjs-toploader
MIT License
622 stars 43 forks source link

No Progress on Server Actions #15

Open maltesa opened 1 year ago

maltesa commented 1 year ago

Thank you for this awesome library. I started using nextjs server actions. Currently, the toploader does not appear when a server action is in progress. It would be awesome if that would work too.

https://github.com/TheSGJ/nextjs-toploader/assets/4067078/a5ee5b39-06b5-4ebd-baea-cc6f2a1cd2b3

ekimcem commented 8 months ago

That would be perfect!

lorikku commented 7 months ago

This is probably out of scope for this library. I think it's specifically made to support Nextjs' linking/navigation system, not for async operations such as server actions. You should handle user feedback when eg. submitting a form yourself.

You can however have more programatic control over the navigation itself (eg. after your server action is complete) using NProgress.

Edit: there's tons of "React topbar loader" libraries out there that are not tailored only to Nextjs' navigation, maybe you should check those out as well.

webdevcody commented 1 week ago

putting this here in case it helps anyone else. If you want to manually show the loader, install nprogress in your project and just do something like this. You can still call redirect inside your server action.

import * as NProgress from "nprogress";

onClick={async () => {
  NProgress.start();
  signOutAction().then(() => {
    NProgress.done();
  });
}}

a utility decorator function such as withTopLoader(signOutAction)(args) might be useful