-
Notifications
You must be signed in to change notification settings - Fork 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
Gutenlypso: Preserve block attributes when updating media #29791
Conversation
Just wanted to confirm that this fixes the original issue for me! It also tested well with the Image, Gallery, Inline Image, Cover and Media & Text blocks. 🎉
My bad, misunderstood! |
}; | ||
|
||
// Block name -> Function that updates the media | ||
mediaBocks = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like in core we don't refresh content at all when any change in the media library happens. I tried the following:
- delete an image using media library, images are missing as soon as you refresh the page
- edit an image using media library - only the image in the currently selected block gets updated, however the old image still works properly for other blocks
So, the short answer is we don't have support for it at the moment at all :(
Regarding finding the ways, I don't think it is straightforward because urls are stored as strings in attributes
section and we simply inline components which handle them. I know that there were some work to strip out image ids when exporting/importing reusable blocks, so maybe @mcsf or @youknowriad would know more how to automate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gziolo for the extra context. I suppose we'll keep thinking about this for core's use case as well. 🤔Maybe we could build something that could query for block functionality. Say, of an editors registered blocks, which ones involve the media library, and it'd return this list or something similar. Or may return a list of blocks instances that satisfy the feature query. I'm guessing we may have other use cases like that.
import MediaStore from 'lib/media/store'; | ||
|
||
const { updateBlockAttributes } = dispatch( 'core/editor' ); | ||
const { getBlocks } = select( 'core/editor' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we'll move away from a single editor store, but I think this usage is okay for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation and analysis @mmtr ! This one was particularly tricky to get a solution in that covers most cases.
Thank you @torres126 for the report and help testing! Much appreciated. ✨
Our custom Media Modal for Gutenlypso relies on
MediaStore.on( 'change' )
for updating the media items when they are edited within the Media Modal itself.But the current approach is triggering an undesired effect: it resets the block attributes to default values (using the
mediaCalypsoToGutenberg
utility) causing the previous values to don't be preserved.Changes proposed in this Pull Request
change
listener out of the Media Modal, so the callback is executed only once per post, instead of once per block.Know issues
This PR doesn't update the media used as featured media for the post or for a simple payment block. A follow-up PR will cover this.
Testing instructions
/block-editor
and select a site under a paid plan (free plans don't allow to edit images in the Media Modal).Editor
Preview
Fixes #29557