Prevent caching on modal popups from a table

I have table that for each row includes 3 actions that individually work fine, and the first one clicked will be correct. But if I subsequently click another in the row (2nd or 3rd), I get the contents of the modal with the first click. I am thinking this is a reference error or caching problem but can't see anything in the documentation that would help me resolve this. Refreshing the page and clicking the second item shows correctly, but now the first item will show the contents of the second (and vice-versa). Can I force the action to always take a fresh instance, or can someone suggest ways I should debug this? Code:
public static function getActions(): array
{
return [
Action::make('view_items')
->modalHeading(fn($record) => 'Item # ' . $record->id)
->modalSubmitAction(false)
->modalContent(function ($record) { return view('components.modals.view-item', [ 'record' => $record, '_nocache' => uniqid() ]); }),

Action::make('view_summary')
->icon('heroicon-o-table-cells')
->url(function ($record) { return view('components.modals.summary', [ 'record' => $record, '_nocache' => uniqid() ])->render();
}),

Action::make('view_detail')
->modalHeading('Detailed Report')
->modalContent(function ($record) { return view('components.modals.report', [ 'record' => $record, '_nocache' => uniqid() // Add random parameter to prevent caching ]); }),
];
}
public static function getActions(): array
{
return [
Action::make('view_items')
->modalHeading(fn($record) => 'Item # ' . $record->id)
->modalSubmitAction(false)
->modalContent(function ($record) { return view('components.modals.view-item', [ 'record' => $record, '_nocache' => uniqid() ]); }),

Action::make('view_summary')
->icon('heroicon-o-table-cells')
->url(function ($record) { return view('components.modals.summary', [ 'record' => $record, '_nocache' => uniqid() ])->render();
}),

Action::make('view_detail')
->modalHeading('Detailed Report')
->modalContent(function ($record) { return view('components.modals.report', [ 'record' => $record, '_nocache' => uniqid() // Add random parameter to prevent caching ]); }),
];
}
9 Replies
islandnuge
islandnugeOP4mo ago
@Dan Harrin - wondering if you may have an idea o this - I've noticed where more than one modal is used in a table row, the contents always load first-clicked on all action events. Is there a way to force unique id's for each action so they don't collide in a cache?
Dan Harrin
Dan Harrin4mo ago
you shouldnt need to clear anything, please open an issue on github with a reproduction repository
islandnuge
islandnugeOP3mo ago
Hey @Dan Harrin - i tried setting up a ticket and creating the project to include but was not able to recreate the conditions on from the forked test project. I'm fairly sure there is something in my project code that is uniquely interfering and introducing this problem as it works as you described in all of my other cases/projects. Would you have any ideas on where I should look to investigate - I attempted to disable all caching in the project (no joy) and the cache-breaking in my sample above. If you have any suggestions on where I could aim that would be joyusly appreciated.
Dan Harrin
Dan Harrin3mo ago
We do not cache anywhere within Filament either so its def not caching which is why its a strange issue try removing lines from the table and seeing which lines might cause it you dont always have to create a minimal reproduction from scratch, you can instead work backwards and create it by reducing your current project
ChesterS
ChesterS3mo ago
Any chance this is because this is a static function? How exactly do you use this? In the resource/table page?
Dan Harrin
Dan Harrin3mo ago
Yeah maybe its how the arguments are passed to the action
stanwarri
stanwarri3mo ago
@islandnuge Were you able to solve this issue? I'm currently experiencing this site wise across one of my app
Dennis Koch
Dennis Koch3mo ago
Similar issue here: #Persistent Livewire Modal State Issue with Multiple Header Actions
islandnuge
islandnugeOP3mo ago
@stanwarri sorry for the delay - nope, still have the same issue, i've worked around it by switching all but one modal to url's so I'm not blocked but I want to get it resolved.

Did you find this page helpful?