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

fix(ui): properly sync field values in bulk upload preventing stale data overriding old docs #9918

Merged

Conversation

akhrarovsaid
Copy link
Contributor

@akhrarovsaid akhrarovsaid commented Dec 12, 2024

What?

This PR fixes an issue where bulk upload on an upload field with hasMany, which had errors on sequential uploads, caused only the last successful upload to be saved to the field value.

Why?

To save all successful uploads to the field value and sync what was shown in the ui to the actual field data.

How?

By triggering a rerender that syncs populatedDocs to the fields value on each sequential successful upload after form errors were resolved.

Fixes #9890

Before:
Bulk-upload-before--Post---Payload.webm

After:
Bulk-upload-after---Payload.webm

Notes:

  • The core issue was that onSuccess function was not properly syncing the correct field values resulting in stale values that would overwrite old docs.

@PatrikKozak
Copy link
Contributor

Hey @akhrarovsaid - Thanks for taking the time to solve this!

I did some digging / testing and your approach does seem to work but I think there is a simpler way to fix #9890

You're right that the onSuccess function is basically stale in the above scenario so you should simply just need to add this effect in the Upload / Input file:

React.useEffect(() => {
    setOnSuccess(onUploadSuccess)
  }, [value, onUploadSuccess, setOnSuccess])

and then remove other usage of setOnSuccess from that file and your current PR changes.

If you want to make this change, I'll review it once more afterwards - if you're busy, I can also go ahead and make a PR for this - let me know!

@PatrikKozak PatrikKozak changed the title fix(ui): sync populated to field value in bulk upload fix(ui): properly sync field values in bulk upload preventing stale data overriding old docs Dec 17, 2024
@PatrikKozak PatrikKozak merged commit 7787105 into payloadcms:main Dec 17, 2024
69 checks passed
Copy link
Contributor

🚀 This is included in version v3.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only one file is saved when uploading multiple images in a multiple field.
2 participants