Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
adds simple logic that keeps authored captions in galleries #15004
Attempted fix for #8310
How has this been tested?
Types of changes
Bug fix (non-breaking change which fixes an issue)
This is not the best fix yet, but it is a quick fix. @noisysocks you had been bitten by the disappearing captions, do you think this approach could work, and later move to calling the REST media api and update the caption for each attachment based on the GTB gallery 's rich text value?
noisysocks left a comment
This makes sense to me. I don't think we need to bother with adding a new REST request. Are there any fields other fields other than
This definitely works better, in that there are no lost captions. That's a massive win on its own.
There's still a couple weird experiences that occur under the following conditions:
It'd be great if we could offer logic to see if the caption has been changed since the Media modal was opened, and then update the caption in Gutenberg to match. Not sure if that's possible though.
If you modify (not delete) the caption in Gutenberg, the caption will not be overwritten by the one in the media modal. When comparing to that, the behavior in step 5 is inconsistent. I'd expect the editor to know that if I've manually deleted a caption, it's intentionally gone and should not be replaced so easily.
In general though, I'm super-glad that this means no more lost captions, so it's a definite improvement.
The only thing that causes it to fail appears to be the new item in block.js (attachmentCaption). All the other code passes all tests (I tested by applying each change incrementally).
As soon as I add
to the block.json the test fails. The error is:
If you test be sure to run
Isn't it missing
Indeed @gziolo that was the issue!
I have refactored the code and now the failing test works.
Instead of adding a caption attribute to each image in the gallery I added an attachmentCaptions array attribute of the gallery ( props @talldan ) and that avoided the need to specify a selector and source.
2 times, most recently
May 24, 2019
@gziolo the bug you found here is not really solvable without tying up the gallery component to the media gallery in WP, as for fixing that we need to monitor the state of the attachments in the modal and only update the component if that state is "dirty".
I would push forward with things as they are, what do you think?