Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STATE: UploadField loads incorrect values #1315

Open
lekoala opened this issue Jan 3, 2023 · 1 comment
Open

STATE: UploadField loads incorrect values #1315

lekoala opened this issue Jan 3, 2023 · 1 comment

Comments

@lekoala
Copy link
Contributor

lekoala commented Jan 3, 2023

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 lekoala/silverstripe-cms-actions#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:

// This tracks changes to the underlying schema data for this field. It may be desirable in
// future to remove this and instead reset redux state whenever a "legacy" form triggers a
// PJAX load. See https://github.com/silverstripe/silverstripe-asset-admin/issues/960
const newFormSchemaFilesHash = md5(JSON.stringify(data.files)).toString();
// If this is the first time this field has mounted, or the schema data has changed (typically
// caused by a PJAX load from saving a legacy non-react form), load the list of files from the
// schema data (data.files)
if (formSchemaFilesHash !== newFormSchemaFilesHash) {
actions.uploadField.setFormSchemaFilesHash(id, newFormSchemaFilesHash);
actions.uploadField.setFiles(id, data.files);
return;
}

Related:
#960
#543
#1001

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

@GuySartorelli
Copy link
Member

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.

@GuySartorelli GuySartorelli changed the title UploadField loads incorrect values STATE: UploadField loads incorrect values Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants