Make WordPress Core

Opened 7 months ago

Closed 6 months ago

#63818 closed defect (bug) (wontfix)

REST API – /wp/v2/media Returns Inconsistent alt_text in Block Editor

Reported by: rahultank's profile rahultank Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.8.2
Component: REST API Keywords: reporter-feedback close
Focuses: accessibility Cc:

Description

When fetching media items via /wp/v2/media/{id} during block insertion in the editor, the alt_text property is occasionally returned as an empty string. This issue occurs especially when the image was inserted into a post before alt text was updated in the Media Library. The editor continues to display the old (empty) alt text until the image is removed and re-inserted.

Steps to Reproduce:
1.Upload an image to the Media Library.
2.Set alt text in the image details.
3.Insert the image into a post via the Gutenberg Image block.
4.Edit the image in the Media Library and change the alt text.
5.Reload the editor and inspect the REST API request to /wp/v2/media/{id}.

Expected Result:
alt_text should always return the current value saved in the Media Library.

Actual Result:
alt_text sometimes returns an empty string or the outdated value.

Environment:
WordPress version: 6.8.2
REST API version: bundled in core
Theme: Twenty Twenty-Five
Browser: Chrome 126 (Windows/macOS)

Change History (6)

#1 @rishabhwp
7 months ago

Reproduction Report

Description

This report validates whether the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.27.5
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 138.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Actual Results

  1. ❌ Error condition did not occur.

Additional Notes

  • Please let me know if I missed anything during testing.

Supplemental Artifacts

https://ffhzlp5fmx.ufs.sh/f/KXY2934aHY4gohuJIGOm7s1e2Zchr4RuU53tKXqCvbQ9fpVS

#2 @SirLouen
7 months ago

  • Keywords reporter-feedback close added; needs-patch removed

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


7 months ago

#4 @joedolson
7 months ago

I am also unable to reproduce this. One thing I'm unclear on is exactly *where* @rahultank is seeing the REST request. Taking the reproduction steps literally, it sounds like you're looking for a request to wp/v2/media in the post editor; which it shouldn't be making once the media is inserted. Inserted media is just part of the post content, and doesn't re-request itself.

If it's an inspection of the endpoint, like what @rishabhwp shows in the video, then I'm also not seeing any issues - the alt text appears as expected.

Are you testing this in a clean environment, @rahultank, with no plugins and a default theme? Is there something we're missing in your reproduction steps?

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


6 months ago

#6 @joedolson
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I'm thinking that @rahultank is expecting the alt text to sync to the post after it's changed.

But that's not what Gutenberg does; changing alt text in the media library is not expected to update posts that reference that image unless they're referencing it programmatically, e.g. featured images.

If this is the scenario, then this is actually behaving as designed. The media library stores a version of the alt text, and that alt text can be used programmatically, but post content is only a specific usage of that media resource, and the alt text in that context is not expected to automatically update to the image. This would break the ability to use the same image in multiple contexts where it may need to have different alternatives.

Note: See TracTickets for help on using tickets.