Skip to content

Image previews are not displayed in the sidebar of image blocks in a WordPress 7.0 + wp-env environment. #76476

Closed

Description

@inc2734

Description

In a WordPress 7.0 + wp-env environment, image previews do not appear in the sidebar of image blocks that reference external image URLs.

It appears to be a CORS error.

It displayed correctly in the Local environment.

Images uploaded to the media library will be displayed correctly in the preview.

Step-by-step reproduction instructions

  1. cd /path/to/directory
  2. npm init
  3. npm install --save-dev @wordpress/env
  4. npm run wp-env start
  5. Install WordPress 7.0 beta5
  6. Go to post edit page.
  7. Place an image block and apply an external image URL.

I referenced https://placehold.jp/1024x768.jpg as the image URL.

Screenshots, screen recording, code snippet

Image

Environment info

  • WordPress 7.0 beta5
  • wp-env
  • TwentyTwenty-Five theme

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

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Type] Bug
    on Mar 13, 2026
  2. added
    [Feature] Media
    [Block] Image
    on Mar 13, 2026
  3. t-hamano commented on Mar 13, 2026

    @t-hamano
    Contributor

    I believe the reason is that crossorigin=anonymous is applied via the addCrossOriginAttribute function:

    Image

    @adamsilverstein @andrewserong, I understand that all external resources in the document are being checked, but is there any way to avoid this issue?

  4. andrewserong commented on Mar 16, 2026

    @andrewserong
    Contributor

    @adamsilverstein @andrewserong, I understand that all external resources in the document are being checked, but is there any way to avoid this issue?

    Good question. Adam might have a better insight here than I do as I'm not 100% sure what our limitations are here, but it seems that this is really down to the CORS policy of the linked image. I.e. if I grab this one from the wordpress.org website, it displays fine:

    Image

    And it has the following response header:

    Image

    Whereas for the image in the issue description, I get this and a CORS error:

    Image

    I think that might have been why we didn't catch it earlier!

    So, a question (likely for @adamsilverstein) — now that we're using the Document-Isolation-Policy as of #75991, would it be safe to remove mutating the img elements so that we can avoid adding crossorigin="anonymous"?

    An alternative, if we do still need that, might be to update the img elements used in media controls like this to fallback to a placeholder image if they're unable to load 🤔

  5. moved this from 📥 Todo to 🗣️ In Discussion / Needs Decision in WordPress 7.0 Editor Taskson Mar 16, 2026
  6. added
    [Status] In Progress
    on Mar 18, 2026
  7. andrewserong commented on Mar 18, 2026

    @andrewserong
    Contributor

    now that we're using the Document-Isolation-Policy as of #75991, would it be safe to remove mutating the img elements so that we can avoid adding crossorigin="anonymous"?

    Just to try to inch toward a fix, I've opened up a PR to try this out in #76618. I'm very much not sure if this is the right approach, but figured it'd be worth trying it out.

    Happy to close it out if there's a better way to go about this!

  8. removed their assignment
    on Mar 18, 2026
  9. andrewserong commented on Mar 18, 2026

    @andrewserong
    Contributor

    Just unassigning myself from this one — I'll be AFK after tomorrow so might not be around to see a fix through.

  10. moved this from 🗣️ In Discussion / Needs Decision to 🏗️ In Progress in WordPress 7.0 Editor Taskson Mar 18, 2026
  11. adamsilverstein commented on Mar 18, 2026

    @adamsilverstein
    Member

    Thanks for the bug report and initial investigation, I am taking another look now.

  12. adamsilverstein commented on Mar 18, 2026

    @adamsilverstein
    Member

    @inc2734 can you confirm if Andrew's PR fixes your issue?

  13. adamsilverstein commented on Mar 18, 2026

    @adamsilverstein
    Member

    So, a question (likely for @adamsilverstein) — now that we're using the Document-Isolation-Policy as of #75991, would it be safe to remove mutating the img elements so that we can avoid adding crossorigin="anonymous"?

    Yes, that seems right. This is no longer needed for img tags and should have been removed when we added DIP. PR looks good to me.

  14. adamsilverstein commented on Mar 18, 2026

    @adamsilverstein
    Member

    I created a core backport PR for this change: WordPress/wordpress-develop#11291

  15. moved this from 🏗️ In Progress to ✅ Done in WordPress 7.0 Editor Taskson Mar 18, 2026
  16. andrewserong commented on Mar 18, 2026

    @andrewserong
    Contributor

    Thanks Adam! I've merged the Gutenberg PR, so I'll give the backport PR a look now.

  17. adamsilverstein commented on Mar 19, 2026

    @adamsilverstein
    Member

    I committed the backport PR (Pascal had approved), hope it looks good to you!

  18. andrewserong commented on Mar 19, 2026

    @andrewserong
    Contributor

    hope it looks good to you!

    It did! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] Image[Feature] Media[Status] In Progress[Type] Bug

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions