How to Disable Table Polling in a Header Action on a Resource List Page?

I'm working with Filament and trying to disable polling for a resource table when a header action is triggered. However, my approach doesn't seem to work.
Here’s my setup:
In MyResource, I define the table with polling enabled:
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->poll('5s')
->columns([ ... ])
...
}
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->poll('5s')
->columns([ ... ])
...
}

In MyResourceListPage, I try to disable polling within a header action:
protected function getHeaderActions(): array
{
return [
Action::make('create')
->mountUsing(fn() => $this->table->poll(null))
...
];
}
protected function getHeaderActions(): array
{
return [
Action::make('create')
->mountUsing(fn() => $this->table->poll(null))
...
];
}

However, this doesn't seem to stop the polling when the action is executed.
Is there a correct way to dynamically disable table polling within an action? Would appreciate any insights!
5 Replies
Dennis Koch
Dennis Koch5d ago
Your approach would work for current requests only. The change is not persisted anywhere. Try writing it to a property $pollingEnabled and use ->poll(fn ($livewire) => $livewire->pollingEnabled ? '5s' : null)
Héctor Q. Torres
OK, I made the change, but it still doesn't work.
I updated my table configuration as follows:
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->poll(fn ($livewire) => $livewire->pollingEnabled ? '1s' : null) // 1s for testing
->columns([ ... ])
...
}
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->poll(fn ($livewire) => $livewire->pollingEnabled ? '1s' : null) // 1s for testing
->columns([ ... ])
...
}
And in my header action:
public $pollingEnabled = true;

protected function getHeaderActions(): array
{
return [
Action::make('create')
->mountUsing(fn () => $this->pollingEnabled = null) // Trying to disable polling
...
];
}
public $pollingEnabled = true;

protected function getHeaderActions(): array
{
return [
Action::make('create')
->mountUsing(fn () => $this->pollingEnabled = null) // Trying to disable polling
...
];
}

However, the polling is still running. Any idea why this isn't working?
Dennis Koch
Dennis Koch5d ago
Maybe that part is just not refreshed. You could try to reload the whole page after that change. Btw. why do you use ->mountUsing() and not ->action()?
Héctor Q. Torres
My reason for using mountUsing was to stop the polling after the action was mounted.
But I am indeed using an ->action().
I managed to make it work in a very improvised way.
The issue is that I have a header action that opens a form, which in turn has a creation option.
Due to polling, I was having problems when trying to submit the open modals because the actions were being disabled between polling intervals.
Another issue was that when filling in some file upload fields, the files would disappear if a polling event occurred while they were still being uploaded.
I searched in various places before coming here and checked this article:
Understanding Laravel Filament V3: Resolving Disabled Action Components on ViewResource with Polling,
but I couldn't find a way to stop the polling when opening the modal and resume it when closing (whether the action was submitted or not).
The way I managed to solve it was by combining your suggestion with the following code:
(The code is in the next message)
(The code is in the next message)
It was improvised, but I managed to enable and disable polling only when the first modal in the chain is opened or closed (regardless of whether the action was submitted or not). If you have a better suggestion, I'd love to hear it!
Medium
Héctor Q. Torres
class ListImports extends ListRecords implements HasForms
{
use InteractsWithForms, ManageLayouts;

protected static string $resource = ImportResource::class;

protected static string $view = 'filament.app.resources.import-resource.pages.list-imports';

protected $listeners = [
'open-modal' => 'disablePolling',
'close-modal' => 'enablePolling',
];

public ?array $data = [];

public $pollingEnabled = true;

public $isHeaderActionOpen = false;

public function enablePolling($id): void
{
if ($this->isHeaderActionOpen) {
$this->isHeaderActionOpen = false;
return;
}

$this->pollingEnabled = true;
}

public function disablePolling($id): void
{
if (!str_contains($id, '-form-component-action')) {
$this->isHeaderActionOpen = true;
}

$this->pollingEnabled = false;
}

...
}
class ListImports extends ListRecords implements HasForms
{
use InteractsWithForms, ManageLayouts;

protected static string $resource = ImportResource::class;

protected static string $view = 'filament.app.resources.import-resource.pages.list-imports';

protected $listeners = [
'open-modal' => 'disablePolling',
'close-modal' => 'enablePolling',
];

public ?array $data = [];

public $pollingEnabled = true;

public $isHeaderActionOpen = false;

public function enablePolling($id): void
{
if ($this->isHeaderActionOpen) {
$this->isHeaderActionOpen = false;
return;
}

$this->pollingEnabled = true;
}

public function disablePolling($id): void
{
if (!str_contains($id, '-form-component-action')) {
$this->isHeaderActionOpen = true;
}

$this->pollingEnabled = false;
}

...
}

Did you find this page helpful?