-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Deleting an image via the media library is not reflected. #23262
Comments
@Fujix1 Thanks for reporting this! I was able to replicate this in Gutenberg 8.4.0 as well and have labeled this as a bug. |
I spent some time looking at the Image Block. I didn't find a suitable fix yet, but here's what I learned in case someone else gets to this sooner: The Image Block attribute values
In order to "force" the MediaPlaceholder to show when <MediaPlaceholder
icon={ <BlockIcon icon={ icon } /> }
onSelect={ onSelectImage }
onSelectURL={ onSelectURL }
notices={ noticeUI }
onError={ onUploadError }
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ { id: isImageDataAvailable ? id : undefined, src } }
mediaPreview={ isImageDataAvailable ? mediaPreview : undefined }
disableMediaButtons={ isImageDataAvailable ? ( temporaryURL || url ) : undefined }
/> The challenge I faced when testing was finding a source of truth. It'd be great to call This means there might be a bit of shuffling around required, for example, rather than relying on the image block attributes for All this seems a bit complex, so I might be missing a more straightforward way of going about things, for instance, a server-side method or something else. |
Adding some notes after chatting with @andrewserong, who has helped with the following advice:
We might be able to utilize the Also |
I spent some more time looking at this issue, a little deflated after trying to wade through the core media js library, and didn't get so far from a technical implementation perspective, but I have questions that might lead us in a productive direction. Within a Gutenberg component, such as useEffect( () => {
if ( ! isSelected ) {
const mediaAttachment = **wp**?.media?.attachment( id );
if (
mediaAttachment &&
mediaAttachment?.destroyed === true
) {
setAttributes( {
url: undefined,
alt: undefined,
id: undefined,
title: undefined,
caption: undefined,
} );
setTemporaryURL( undefined );
}
}
}, [ isSelected ] ); However I think a better option might be to have core media library trigger an event in the attachment model, perhaps in the callback of the delete HTTP request. "Better" because consumers of I'm not very familiar with Backbone.js so perhaps listening to the Out of interest, here's where the UI event to delete the attachment is set: https://github.com/wordpress/wordpress-develop/blob/9bac3d3401554592d424c47ab2f0b35b309f1293/src/js/media/views/attachment/details.js#L151 Imagining we've got that far, we'd then have to allow the the Gutenberg MediaUpload utils to listen out for a delete attachment event, either on the collection or the selected attachment. I'm not sure how to do this quite yet. In Gutenberg, we listen to |
Thanks for digging in further to this one @ramonjd! I think you've already covered this, but If we can, it'd be great to try to keep any of the media library logic tucked inside the media upload component in the
This sounds like a good approach to explore. I'm not quite sure how the Backbone code works, but in the Attachment model's From a quick read of the Backbone JS docs on collections it sounds like there are some inbuilt events whenever changes occur on a model (under the Catalog of Events heading further down the page). So 🤞 we might be able to listed for |
@ramonjd - wp.media will trigger an event when an item is removed from the library, you can listed for something like |
@adamsilverstein 🙇 Thank you so much! I'll try it out. Edit: this also works: this.frame.listenTo(
wp.media.model.Attachments.all,
'remove',
( attachmentObject ) => attachmentObject.destroyed ? console.info( 'It be gawn, dawg!' ) : null;
);
|
I think we can go with the solution described here but make it non-destructive. If an image is missing, the block doesn't reset its attributes; instead, we display Some technical notes:
|
This seems okay if we can think of an approach that is truly generic across any content that drifts out of sync. Coming to mind is not just images, but also videos, files, sound bits, and even navigation blocks where the nav CPT itself gets deleted. Conceptually those are all the same: the markup refers to something that's not there anymore. The one take-away I have, to avoid #64288 again, is that the placeholder pattern is not a good place to show error messages. To that end, my instinct would be to go towards what the web-browser we all use has established as a pattern for similar cases: showing a broken symbol. We can do that, and better, by showing error information in the inspector, where there's room to both be verbose, and provide actions to help address the situation. Separately, and this should be tracked somewhere, on my mind is a "linting" panel, perhaps it exists in the document outline, or in the prepublish flow, or both, that exists to surface warnings and errors for your document, just like an IDE does. Anything from broken image to insufficient contrast, poor SEO or missing API key. |
Exactly! A while ago, I read an article about styling broken images via CSS, which took a similar approach. I think we need a design for a similar component - We could also provide error info via this component since it would be the "same" for all the core blocks - the entity for the provided ID is missing from the server. |
If we start with the image, then some kind contributor has designed this in the Icon library: That's this SVG:
My instinct would go towards using that:
If we choose to expand to additional broken filetypes, we can either use the same pattern to make broken versions of video, file, etc, or make a generic broken item icon we can use. But if you agree, it may be fine to start here. |
Thank you for reviving this issue @Mamaduka and @jasmussen I'm not sure when I'll get a chance to return to it, but it'sgreat to have these notes. |
Deleting an image permanently on the media library is not reflected to the related image block.
Step to reproduce
Expected behavior
The image should be removed from the image block in sync with the media library, and the image itself is to be deleted from the server.
Screenshots
Editor version (please complete the following information):
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: