livewire / volt

Volt is an elegantly crafted functional API for Livewire.
https://livewire.laravel.com/docs/volt
MIT License
346 stars 20 forks source link

Batch callbacks are not working when dispatched in a component. #115

Closed KozSuper closed 2 months ago

KozSuper commented 2 months ago

Volt Version

1.6

Laravel Version

11.9

PHP Version

8.3

Database Driver & Version

No response

Description

When creating a Batch with callbacks like progress, then, catch, finally, these callbacks are not working as expected. Everything works fine in the Controller.

Steps To Reproduce

new class extends Component {
    public function mount(){
      $jobs = //somejobs 
      $batch = Bus::batch([
        $jobs
      ])
      ->before(function (Batch $batch) {
          //working
      })->progress(function (Batch $batch) {
        // doesn't work
      })->then(function (Batch $batch) {
        // doesn't work
      })->catch(function (Batch $batch, Throwable $e) {
        // doesn't work
      })->finally(function (Batch $batch) {
        // doesn't work
      })->allowFailures()
      ->dispatch();
    }
}; ?>
KozSuper commented 2 months ago

image

I think it's because of a serialization error. It can't be unserialized when dispatching in a Volt component.

driesvints commented 2 months ago

Think it's best you use a service class then for this one and use that in your Volt component. We'd always appreciate a PR to the docs if you discover an incompatibility.