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

Image block: caption persists when replacing image #62468

Open
afercia opened this issue Jun 11, 2024 · 2 comments
Open

Image block: caption persists when replacing image #62468

afercia opened this issue Jun 11, 2024 · 2 comments
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented Jun 11, 2024

Description

When replacing an image that does have a caption with another image that does not have a caption, the previous caption persists.

I can reproduce thie behavior on WordPress 6.5 and on Gutenberg trunk.

Attached animated GIF to illustrate:

caption persists

Step-by-step reproduction instructions

  • Create a new post.
  • Add an Image block from the Media Library, make sure the image does have a caption.
  • Observe the image does render its caption.
  • Click 'Replace' in the image block toolbar.
  • Replace the image with one that does not have a caption.
  • Observe the caption of the previous image persists.
  • Expected: the caption to not be redered.

Note: when replacing with an image that does have a caption, the caption is correctly updated.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@afercia afercia added [Type] Bug An existing feature does not function as intended [Block] Image Affects the Image Block labels Jun 11, 2024
@t-hamano
Copy link
Contributor

I think this is because there's a process to ensure that caption text isn't overwritten by an empty caption.

// If a caption text was meanwhile written by the user,
// make sure the text is not overwritten by empty captions.
if ( captionRef.current && ! mediaAttributes.caption ) {
const { caption: omittedCaption, ...restMediaAttributes } =
mediaAttributes;
mediaAttributes = restMediaAttributes;
}

Do you think this process is unnecessary?

@afercia
Copy link
Contributor Author

afercia commented Jun 18, 2024

I understand the intent of that check but seems to me it is based on an assumption. To me, it is only valid in a scenario where the user has written a new caption and it is still making a decision on what image to use or wants to replace the image with one that fits with the existing caption. Maybe they are trying various images and in that case it makes sense to not lose the caption. But this is an assumption on a single case.

As a user, when I replace an image with a new one that has its own caption, I expect the caption to be there.

Edit: Also, comparing the behavior with the one that always existed in WordPress and now it's in the Classic editor, this is a change in the expected behavior that should have been considered a little more deeply IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended
2 participants