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

Media: Inserting media that hasn't been added yet causes errors. #31230

Closed
kwight opened this issue Mar 5, 2019 · 9 comments
Closed

Media: Inserting media that hasn't been added yet causes errors. #31230

kwight opened this issue Mar 5, 2019 · 9 comments
Assignees
Labels
[Feature] Post/Page Editor The editor for editing posts and pages. [Goal] Gutenberg Working towards full integration with Gutenberg [Pri] High [Type] Bug

Comments

@kwight
Copy link
Contributor

kwight commented Mar 5, 2019

When setting a featured image, we can access the Pexels API from the "Free Photo Library" dropdown in the media modal. As soon as we select an image, we can immediately insert it (with the primary action button), even though it hasn't completed uploading to our library.

In Calypso, this will give console errors but corrects itself somehow; however, when using the media modal with an iframed block editor, the failure will leave the featured image loader spinning forever unresolved.

Additionally, you'll get the same console errors when trying to insert a still-uploading image in the block editor, but it works itself out with no issues. Only in the context of the featured image in the block editor is this an issue.

The core media modal gets around this by not allowing you to insert an image until it has been uploaded. (Seems this could be a possible solution, though not as slick a UX.)

screen shot 2019-03-05 at 1 45 35 pm

screen shot 2019-03-05 at 1 45 50 pm

Note that if we then remove the featured image, we can reapply it successfully, since the media has completed uploading.

#12000 may point to a solution.

To Replicate

  • At https://wordpress.com/post, select a site that's opted in to the block editor.
  • Select Set Featured Image, and choose Free Photo Library from the top left corner dropdown.
  • Enter a search term, select an image, and click Insert.
  • Note the console error, and the missing featured image.

(You can also replicate this by uploading a local picture and then inserting it as a featured image before it has finished uploading.)

Note: after resolving this issue, also make sure you can no longer reproduce #33362.

@kwight kwight added [Feature] Post/Page Editor The editor for editing posts and pages. [Goal] Gutenberg Working towards full integration with Gutenberg labels Mar 5, 2019
@donalirl
Copy link

donalirl commented Jun 2, 2019

This came up in #5711931-hc (follow-up #2077994-zen.) We did not succeed with the workaround of removing the featured image and re-selecting it from the site's Media. It must be some theme/plugin conflict because it did work fine on my atomic site.

@noahtallen noahtallen self-assigned this Jul 25, 2019
@noahtallen
Copy link
Member

noahtallen commented Jul 25, 2019

The console errors are caused because the media modal does the following synchronously:

  1. Assigns the images a temporary IDs before uploading
  2. Calls the code to upload the items
  3. Returns immediately (i.e. before the upload is done)
  4. Then whatever context you opened the modal from gets the images with their temporary IDs, since they have not yet finished uploading.
  5. That context (i.e. the image block or the featured images sidebar area) immediately performs a GET for the image, like https://public-api.wordpress.com/wp/v2/sites/160923989/media/media-15. In this case, media-15 is the transient (temporary) ID of the media that is currently uploading and obviously doesn't exist on the backend.

The blocks recover from this because in calypsoify-iframe, we listen for changes in the media store and post an updateImageBlocks action when the upload is finished. The handler for this action is also supposed to update the featured image, so my hypothesis is a bug in this function:

function updateFeaturedImagePreview( image ) {

@noahtallen
Copy link
Member

noahtallen commented Jul 27, 2019

Turns out the above is unrelated - the code we have for update image blocks is specifically for editing an image (see D26023-code) and doesn't fire when inserting an image in the first place.

I'm not sure how the core Gutenberg image block (source code here) recovers from receiving the transient ID, while the featured image selector (source code here) does not. Both core image blocks and the featured image selector use the getMedia selector on the core data store to retrieve the picture, so I'd assume that the bug would happen after that at some point.

I was unable to find a solution / cause during HACK week, so I'm sending it back to the backlog.

@arunsathiya
Copy link
Contributor

arunsathiya commented Sep 5, 2019

This was reported here #35987 as well, and I am able to reproduce. I also noticed that, when the featured image is removed and when I open the media library again, the photo from Free photo library can be seen.

That is, the featured image action fails, and when we remove that image to check the media library, the file can be seen to be successfully uploaded.

Screenshot 2019-09-05 at 08 24 51

Screenshot 2019-09-05 at 08 24 54

But, trying to set new images as featured again, from Free photo library, fails.

@kwight
Copy link
Contributor Author

kwight commented Oct 4, 2019

Confirmed this is still an issue today, but didn't get far on a solution.

@zdenys
Copy link
Contributor

zdenys commented Nov 5, 2019

Confirming that it is still happening and I encountered it many times during Quick Start Sessions.

@zdenys
Copy link
Contributor

zdenys commented Jan 28, 2020

As per pbAPfg-1z-p2#comment-94 it should not be happening anymore. Can others confirm this too so we can close the issue?

@gwwar
Copy link
Contributor

gwwar commented Jan 28, 2020

Let's verify if this is still an issue

@gwwar gwwar self-assigned this Jan 29, 2020
@gwwar
Copy link
Contributor

gwwar commented Jan 29, 2020

@zdenys this was fixed by @Addison-Stavlo in #38488 💖

The insert button will be disabled until the image is fully uploaded.

Jan-29-2020 14-22-21

@gwwar gwwar closed this as completed Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Post/Page Editor The editor for editing posts and pages. [Goal] Gutenberg Working towards full integration with Gutenberg [Pri] High [Type] Bug
Projects
None yet
Development

No branches or pull requests

6 participants