Closed
Description
I have a WheaterWidget
with a refresh
action that can be invoked with the data-pool
option or a button click:
#[AsLiveComponent]
class WheaterWidget
{
public function __invoke(): void
{
$this->refresh();
}
#[LiveAction]
public function refresh(): void
{
// Update component internal state
}
}
Here is the behaviour:
- With
<twig:WheaterWidget defer />
method__invoke
is called -> widget is refreshed as soon as it loads - With
<twig:WheaterWidget />
method__invoke
isn't called -> widget isn't updated
I want to make it work (refreshed as soon as it loads) with or without defer. So I added a [PostMount]
attribute to refresh
:
#[LiveAction]
#[PostMount]
public function refresh(): void
{
// Update component internal state
}
And this, indeed, make the widget behave correcly for case 2... but then adding a defer
will make it refresh twice (both __invoke
and refresh
are called).
So what's the correct way to handle this kind of situation?