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

Lock post saving during image uploads #41120

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented May 18, 2022

What?

Fixes #39223

Improves the media upload experience and prevents saving/publishing while images are still uploading.

Why?

When users are uploading media and navigate away, uploads and image display break.

Gutenberg displays an "Unsaved Changes" warning if users try to navigate away from the editor with unsaved changes (triggered by window.beforeunload). The check for unsaved changes misses images that are still being uploaded allowing users to navigate away while WordPress is still uploading or processing an image.

In progress uploads may never complete regeneration if PHP is able to generate all sub sizes in one go, because our retry mechanism will not fire. Regardless, Gutenberg will continue marking the image as "in progress" with a spinner when the upload doesn't complete.

How?

Locks the save/publish mechanism until all image uploads have completed.

Testing Instructions

  1. Create a new post and publish it.
  2. drag in one or more very large images that will take several seconds to be processed
  3. before image processing completes, hit update to update the post
  4. click view post to navigate away
  5. the image may or may show, the srcset will be incomplete (missing sizes)
  6. edit the post again, note the images are stuck in an uploading state.

Screenshots or screencast

share.getcloudapp.com/8LuDGjnD

image

@adamsilverstein adamsilverstein requested a review from Mamaduka May 18, 2022 20:12
@mtias mtias added the [Feature] Media Anything that impacts the experience of managing media label May 22, 2022
Copy link
Contributor

@ryanwelcher ryanwelcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a couple of comments.

packages/editor/src/utils/media-upload/index.js Outdated Show resolved Hide resolved
packages/editor/src/utils/media-upload/index.js Outdated Show resolved Hide resolved
@adamsilverstein
Copy link
Member Author

@ryanwelcher / @Mamaduka - I cleaned this up a bit and this code now does lock the publish/update buttons while image uploads are processing, however I noticed some issues remain I'm not sure how to address...

  • if you delete an image block while it is uploading, post publishing will never unlock. I guess we could catch this when the component is unmounted?
  • the "Save draft" button is not disabled, if you click this during an image upload, the post will be saved in a broken state (exit and revisit the page and you will see it is perpetually loading the image)
  • nothing warns users if they navigate away during an upload

I feel like we may need an additional editor store attribute for "imagesUploading" added to the conditionals, or maybe we can tap into experimental "entity saving" logic instead? or maybe we can somehow change isSaving or forceIsSaving - basically the editor shows the correct state during saves, and in a sense the image are being saved so it feels like the right fit, but i'm not sure how to control it or if we need another attribute.

Copy link

github-actions bot commented Jul 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: ryanwelcher <welcher@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: mtias <matveb@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein
Copy link
Member Author

@Mamaduka I updated the PR against trunk and it should be ready for review. I am open to suggestions for a better mechanism and also I'm not sure what may have changed in the interim that could make this cleaner.

@annezazu pinged me recently about this though, so I guess it is still an issue.

@annezazu
Copy link
Contributor

annezazu commented Jul 2, 2024

Just tested this and can confirm the option to save remains greyed out while you have a photo uploading, making for a clearer experience:

no.option.to.update.mov

This is compared to the current experience:

current.experience.for.media.upload.mov

@ellatrix
Copy link
Member

ellatrix commented Jul 4, 2024

Perhaps I am doing something wrong, but I'm not seeing a disabled save or publish button while an image is uploading:

Screenshot 2024-07-04 at 14 30 35

Or is locking not disabling the buttons? If not, it probably should be?

@ellatrix ellatrix added the [Type] Bug An existing feature does not function as intended label Jul 4, 2024
@adamsilverstein
Copy link
Member Author

Or is locking not disabling the buttons? If not, it probably should be?

Looks like this is currently not locking the Publish button, only the Save button after you have published a post. Something must have changed with the publish button state, this was working previously...

Can you try testing with an already published post? In the meantime, I'll try fixing the publish button, I guess there are two now, the initial button:
image

and then the confirmation publish button -
image

(which could already be open when an image is uploaded). I guess for now the second button at least should be disabled during media uploads.

@adamsilverstein
Copy link
Member Author

@ellatrix - actually, I wasn't testing correctly, this works as expected. the inner "publish confirmation" button is what gets disabled for an unpublished post.

To test, first open the publish confirmation panel by clicking the initial publish button. then try uploading one or more very large image(s) (or throttle your network connection). note the inner publish button is disabled for the duration of the upload(s).

image

after clicking this button you see another publish button that I am calling the publish confirmation button:

image

Here is a quick screencast, in it you can see I added some console logging as each image upload locks saving and then unlocks it when uploading completes.

Monosnap.screencast.2024-07-08.14-53-35.mp4

@adamsilverstein adamsilverstein requested a review from ellatrix July 18, 2024 15:57
@adamsilverstein
Copy link
Member Author

any additional feedback @ellatrix @Mamaduka or @youknowriad?

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me 👍

It feels perfect for an e2e test but can also be done separately.

@youknowriad
Copy link
Contributor

I think the PR description deserves to be expanded a bit. We should not expect reviewers to click all the links to be able to understand what's happening here.

@youknowriad
Copy link
Contributor

I think you need to run npm install to fix the package lock (the failing test here)

@adamsilverstein
Copy link
Member Author

I think you need to run npm install to fix the package lock (the failing test here)

done

@adamsilverstein
Copy link
Member Author

I think the PR description deserves to be expanded a bit. We should not expect reviewers to click all the links to be able to understand what's happening here.

Expanded with details from the Issue.

@youknowriad youknowriad enabled auto-merge (squash) July 22, 2024 13:42
@youknowriad youknowriad merged commit a23699c into WordPress:trunk Jul 22, 2024
59 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.9 milestone Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsaved changes should consider image uploads in progress
8 participants