spatie / livewire-filepond

Upload files using Filepond in Livewire components
https://spatie.be/open-source
MIT License
195 stars 10 forks source link

[Bug]: Livewire property not updated when image removed #4

Open edwinvdpol opened 1 month ago

edwinvdpol commented 1 month ago

What happened?

When you remove an image from Filepond, the image itself is deleted from the filesystem, but the Livewire property isn't updated. When you revert an new uploaded image from Filepond, the Livewire property is removed and generates this error:

Property [$image] not found on component: [...]

It also doesn't delete the file from the temporary directory in this case, because this only happens when the $property is an array.

How to reproduce the bug

When the image already exists and is filled (edit form), and I remove the image (click the X icon), it removed the file from the filesystem. When you inspect the Livewire component data, it is still filled.

When the image is empty, and I upload an image, and click the revert image (the X), it gives the error.

Package Version

1.0.2

PHP Version

8.2.21

Laravel Version

v11.16.0

Which operating systems does with happen with?

macOS

Notes

I added the following line in the remove method in my component, which overwrites the one in the WithFilepond trait. This works for me, as my property is nullable, not sure how to generally fix it tbh.

...

data_set($this, $property, null);

You could also fire an file-removed event for example when a file is deleted.

Not sure about 'the best' solution. 😉

riasvdv commented 1 month ago

I'd accept a PR that sets the property to null (It should work with just doing $this->$property = null, the property needs to be nullable anyway I think if you want to use Livewire file uploads

rabol commented 1 month ago

I have a similar issue if the validation of the uploaded file fail, then the error messages is not cleared when the file is deleted

devhereco commented 1 month ago

@edwinvdpol check this #9