silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
20 stars 79 forks source link

STATE: UploadField loads incorrect values #1315

Open lekoala opened 1 year ago

lekoala commented 1 year ago

Affected version : 4.* (tested in 4.12)

The UploadField state depends on a md5 hash of files. This doesn't always work, in particular in the cms (model admin) when the ID stays the same between records (ex: Form_ItemEditForm_Image). The same id being used, navigating between the records AND saving (so this only happens in my cms-actions module where you can save & next https://github.com/lekoala/silverstripe-cms-actions/issues/27) leads to files being displayed again on the next record.

This means that in the current state, even if you have a default state without files data-state="{"name":"Images","id":"Form_ItemEditForm_Images","value":{"Files":[]},"message":null,"data":{"files":[]}}" you will end up with files being displayed regardless.

i'm not sure relying a on hash of files is a proper solution for this: https://github.com/silverstripe/silverstripe-asset-admin/blob/487e62c4550fe187f643e1a8226f840b7e9f9260/client/src/components/UploadField/UploadField.js#L67-L79

Related: https://github.com/silverstripe/silverstripe-asset-admin/issues/960 https://github.com/silverstripe/silverstripe-asset-admin/issues/543 https://github.com/silverstripe/silverstripe-asset-admin/issues/1001

My temporary fix: append a random suffix to the id, and therefore it gets a distinct state.

GuySartorelli commented 1 year ago

The md5 solution isn't perfect - as the comment hints at and as discussion on the PR that introduced it points out (and as is discussed on at least one of the issues you linked to) there is a deeper redux puzzle here which needs to be resolved for assets. The correct solution here is to spend some time looking at how we use redux - which is not something the core team is likely to do in the near future.

I'll leave the issue open for now - the more issues related to this that get reported, the easier it will be to justify dedicating time to solving this overall problem.