Problem/Motivation
The loading UI appears to be ignored for media images displayed as thumbnail.
When loading is set to eager it still displays as lazy.
Changing loading in /admin/structure/media/manage/image/display to eager does not fix this (nor should it).
Regular image fields work correctly.

The only way I've found to get a media image to display as eager is to set the image loading in /admin/structure/media/manage/image/display. Then use rendered entity rather than thumbnail. But this forces all media that wants to use eager to use the same image style.
Steps to reproduce
- Create a new Drupal instance
- install the Media Module
- Add a media image field to some content
- in manage display set the image to thumbnail
- open the loading settings for the thumbnail and set it to "eager"
- create that content and add an image to it
- look at the html for the img and it has the property loading="lazy" instead of "eager"
Proposed resolution
Fix whatever is overriding/ignoring the loading argument in the media image field.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | 3307409-25-10.0.patch | 2.56 KB | mherchel |
| #25 | 3307409-25-9.5.patch | 2.56 KB | mherchel |
| #25 | 3307409-25-9.5-TEST-ONLY-FAIL.patch | 978 bytes | mherchel |
| #25 | 3307409-25-10.0-TEST-ONLY-FAIL.patch | 978 bytes | mherchel |
Issue fork drupal-3307409
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Phoenixbros commentedComment #3
diegorsComment #4
diegorsComment #5
gquisini commentedI'll try to work on this one
Comment #7
gquisini commentedI followed the steps and saw the wrong property. After some debugging, I found a possible way to fix the problem. I made some changes in
MediaThumbnailFormatter::viewElements()to set theloadingattribute.I believe that the automated tests will be required to validate the changes, so I will move the issue to NW.
Comment #10
mherchelJust ran into this (and opened up duplicate #3331060: Setting media field to loading="eager" doesn’t work when using the media_thumbnail field formatter.
This still happens in 10.1.x. Updating and editing issue summary.
Comment #11
heddnPosted some feedback on the MR. Also could use some test coverage to make sure we don't regress here.
Comment #12
bbu23Patch MR !2873 works for me on Drupal 10.0.4.
Comment #13
heddnStill NW for addition of tests and the MR feedback.
Comment #15
heddnThis adds tests and responds to the feedback on the MR. Since I didn't have access on the original MR to change its base, I've opened a new on that is set to merge into 10.1.x.
Comment #16
mherchelVerified that the MR in #14 resolves the issue. I tested both eager and lazy loading, and the patch works as expected.
I'm attaching the test as a patch to ensure that it fails properly. Assuming that the patch containing the tests fail, this is RTBC.
I also hope we can backport this to 9.5.x, as this is a bug that'll likely affect a number of sites.
Comment #18
mherchelTest only patch failed! RTBC!
Comment #20
mherchelComment #22
catchCommitted/pushed to 10.1.x, thanks!
Comment #23
mherchelyay!
@catch: would it be appropriate to also backport this to 9.5.x and 10.0.x?
This is something that I've run into several times in my projects :D
Comment #24
catchWe could but it would be nice to get 10.0 and 9.5 test runs.
Comment #25
mherchelMakes sense!
Patches are attached. Note this is the exact same patch as the commit in #21
Comment #26
mherchelTest runs completed. Setting to RTBC so it doesn't slip through the cracks. Thanks!
Comment #29
catchBackported to both branches, thanks!
Comment #30
mherchelThank you!