Skip to content

suffixAction() callback does not receive updated model collection when updated by same entry component #17598

@harvey-4thd

Description

@harvey-4thd

Package

filament/filament

Package Version

v4.0.4

Laravel Version

v12.26.3

Livewire Version

v3.6.4

PHP Version

PHP 8.3.0

Problem description

When a suffix action is provided to an infolist entry as a callback it fails to update when the relationship updates from the same entry.

The callback in question:

->suffixAction(function (User $user) {
    $documents = $user->documents->count();

    return  Action::make('download')
        ->requiresConfirmation()
        ->badge()
        ->label($documents)
        ->action(function () {
            Notification::make()
                ->title('Downloading')
                ->send();
        });
})

Removing it from the callback, it updates just fine.

->suffixAction(
    Action::make('download')
        ->requiresConfirmation()
        ->badge()
        ->label(fn(User $user) => $user->documents->count())
        ->action(function () {
            Notification::make()
                ->title('Downloading')
                ->send();
        })
),

Expected behavior

I would expect the callback passed to the suffixAction method to update and receive an updated collection when a relationship is updated from an action on the same entry.

This is needed when you want to render two different versions of a suffix action depending on relationship collection (e.g. download single vs download in modal).

Steps to reproduce

  1. Clone rep, migrate & run seeder.

  2. Login with [email protected] & password.

  3. Navigate to /admin/user/1.

  4. Use the upload action on the left 'Works' entry and see that the suffix action on the other entry updates as normal.

  5. Use the upload action on the right Does not work entry and see that the suffix action on the same entry does not update, even though the state updates as expected.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/harvey-4thd/filament-relation-cached-in-suffix-action-callback

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions