#Filament v4 ->state uses cached values?

8 messages · Page 1 of 1 (latest)

sullen coral
#

I upgraded from Filament v3 and noticed some behaviour.

So i have this piece of Code. We were using ->getStateUsing in v3 but ->state ist in de API doc so we changed it. Under the hood it is the same so it doesnt matter anyways.

TextColumn::make('name')
                ->label('Name')
                ->state(function (UserPermission $record) {
                    $userMemberdata = $record->user->getUserMemberData();
                    dump($userMemberdata->first_name . ' ' . $userMemberdata->last_name);

                    return $userMemberdata->first_name . ' ' . $userMemberdata->last_name;
                }),

The Field in make does not exist - so name does not exists on the Record. It always has beed calculated on the fly
Behaviour in v3: Every Row has the correct name
Behaviour in v4: Every Row has the same name

Also i added a dump and noticed it is only executed in the first row - so I think the value is chached somehow. Could't find anything in the docs https://filamentphp.com/docs/4.x/tables/columns/overview#setting-the-state-of-a-column

I also tried ->formatStateUsing but this method is not executed if the value of make - so the property - does not exist.

I'm missing something but kinda stuck right now. Using Filament v4.1.10

serene spireBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

sullen coral
#

Well it seems formatStateUsing is working if default(1) isset. So maybe this is the way to go for such calcuated field for which the field name does not exists.

gilded plank
sullen coral
#

Well this is a simplified example - we have used the getStateUsing quite much -> Cannot make a virtual Column for everything 😄

As for now i haven't found a practiable solution. I don't think this is a bug - more like a different behaviour because of the new caching in V4. Different behaviour -> might have to change something in our code.

echo marsh
sullen coral
#

Will do - unfortunately nothing worked yet

sullen coral
#

@dim egret any idea on this? or a hint where to look?