laravel-livewire-tables: [Bug]: Multiple dispatch when a method is executed via an event
What happened?
Multiple dispatches are generated when executing a method through an event that in turn triggers another event.
app.js or DeviceTable.php
Livewire.dispatch('load-token', [true]);
$this->dispatch('load-token', true)->to(Device::class);
Device.php
#[On('load-token')]
public function token(bool $status) : void {
if ($status) {
// ...
$this->dispatch('get-hostname');
}
}
Out:
{
"components": [
{
"snapshot": "...",
"effects": {
"returns": [
null
],
"html": "...",
"dispatches": [
{
"name": "get-hostname",
"params": []
},
{
"name": "get-hostname",
"params": []
},
{
"name": "get-hostname",
"params": []
},
{
"name": "get-hostname",
"params": []
}
]
}
}
]
}
How to reproduce the bug
- Create a component.
- Add a method that listens to an event.
- Add a dispatch in the method.
- Dispatch the event for the second executive event.
Package Version
dev-v3-develop
PHP Version
8.2.x
Laravel Version
10.23.1
Alpine Version
3.13.0
Theme
Tailwind 3.x
Notes
If I delete this part of the code from the LaravelLivewireTablesServiceProvider.php file on line 49 it no longer launches multiple events, unfortunately I don’t understand what exactly these lines do.
if (config('livewire-tables.inject_assets', true) === true) {
(new RappasoftFrontendAssets)->boot();
app('livewire')->componentHook(AutoInjectRappasoftAssets::class);
ComponentHookRegistry::boot();
}
Error Message
No response
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 17 (3 by maintainers)
Fix should be in develop by mid week, spoke to the LW core team, functionality of this changed between when I wrote it in a preview and the released version.
@jacksontong - This should be in v3-develop now, just ran a quick test and got a single dispatch of an event.
To replicate, I used: public function which just has a ($this->dispatch) method in it:
Then: View with an on-click binding to the function View with a wire:click binding to the function View with a dispatch event
Tested all three approaches, example of test result from a wire:click
I may be missing something, so let me know if you still have issues, or if I’ve introduced a world of pain!
@joserick - Note that this should be resolved (I believe) in v3-develop, unless someone says otherwise!
I will be merging v3-develop into v3-master, and then onto a proper beta release by the end of the weekend, with a view to having an official v3 not too long after that, thanks to everyone using the develop branches.
Awesome! Glad to hear it.
Please do raise any other issues on here, and feel free to give me a prod on Discord, or tag me in the issue, there’s one or two very minor bugs I’m aware of (which involve all kinds of edge scenarios), and a couple of new features that I’m trying to finalise prior to getting the official beta out.
I really, genuinely appreciate your patience, and the awesome feedback, and detailed info throughout the beta period that helps identify the issues (95% of the battle).
I was oh-so-keen to get it released shortly after LW3 was released, but wanted to instead take the opportunity to adjust the code so that it’s easier to deliver new features, performance enhancements etc, as it’s rare that there’s the opportunity to really drains-up the codebase.
We should be back to normal in the coming days 😃
Hmm, it’s entirely possible I’ve missed off a merge, give me 20 mins, as that v3-develop branch definitely doesn’t have the fix