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

Closed
afercia opened this issue Jun 11, 2024 · 7 comments
Closed

Image block: caption persists when replacing image #62468

afercia opened this issue Jun 11, 2024 · 7 comments
Labels
[Block] Image Affects the Image Block [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [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.

@MadtownLems
Copy link

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

This is my take as well. If I replace an Image block that already has a set caption (in the media library), I'd expect that to replace the one of the image i was using previously.

@t-hamano
Copy link
Contributor

If I replace an Image block that already has a set caption (in the media library), I'd expect that to replace the one of the image i was using previously.

I think this is already the case:

9dc4036c748b68e342e870683a9aa970.mp4

I think the point here is whether to keep the previous caption if the caption of the newly replaced image is empty, or to make it empty.

By the way, in the classic editor, it seems that the caption of the replaced image always takes priority, regardless of whether the caption is empty or not.

f260eb9a14a464ad7e398b1fd4d4c7e5.mp4

@t-hamano
Copy link
Contributor

Contrary to this issue, it is also worth noting that some users consider the caption being replaced with the new image's caption to be a bug.

#66979

@Mamaduka
Copy link
Member

Found another related issue - #42834.

I think we need to consolidate these into a single issue and agree on some 80/20 behavior and implement it.

@t-hamano
Copy link
Contributor

Thanks for pointing me to another issue.

Let's close this issue and continue the discussion in #42834.

@t-hamano t-hamano closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2024
@t-hamano t-hamano added the [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed label Nov 26, 2024
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 [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants