[V3] Removing upload from FileUpload does not trigger `afterStateUpdated`

Hiya! Testing our project on V3 and found this bug(?) or at least unexpected behaviour. I have this FileUpload field in a form with multiple files allowed. Whenever you upload a file I need to execute some code, which I do using afterStateUpdated. This works perfectly fine for adding files, but it's not called when you remove a file.
FileUpload::make('uploads')
->multiple()
->storeFiles(false)
->afterStateUpdated(function (array $state, Get $get, Set $set) {
collect($state)->map(fn (TemporaryUploadedFile $file, $key) => do_something());
}),
FileUpload::make('uploads')
->multiple()
->storeFiles(false)
->afterStateUpdated(function (array $state, Get $get, Set $set) {
collect($state)->map(fn (TemporaryUploadedFile $file, $key) => do_something());
}),
8 Replies
Dan Harrin
Dan Harrin2y ago
i dont think this has changed in v3 its probably also in v2 you can submit a PR to fix it if you want, preferably to v2 since we dont provide v3 support in this case, what are you trying to do?
Dennis Koch
Dennis Koch2y ago
I guess: Uploading is handled on the server side. Removing only on client side until the form is saved.
Thandruil
ThandruilOP2y ago
No it's actually sending a message to server. So upload uses Livewire's native finishUpload which calls syncInput (and thus afterStateUpdated) Remove calls Filament's own removeFormUploadedFile which only sets the state using state(...)
Dan Harrin
Dan Harrin2y ago
there is a way to trigger the afterstateupdated if we want to which we can do in removeFormUploadedFile or the equivalent method in the fileupload
Thandruil
ThandruilOP2y ago
Yeah that's the fix I was thinking about as well
Dan Harrin
Dan Harrin2y ago
or just call syncinput but i'd rather not do that as i know for sure that will break lw3 lol
Thandruil
ThandruilOP2y ago
yeah fair is there a way in user land to trigger the afterStateUpdated somehow? I tried listening to updated$propname but to no avail
Dan Harrin
Dan Harrin2y ago
im guessing callAfterStateUpdated() but i might be wrong
Want results from more Discord servers?
Add your server