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

  1. Create a new Drupal instance
  2. install the Media Module
  3. Add a media image field to some content
  4. in manage display set the image to thumbnail
  5. open the loading settings for the thumbnail and set it to "eager"
  6. create that content and add an image to it
  7. 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.

Issue fork drupal-3307409

Command icon 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

Phoenixbros created an issue. See original summary.

Phoenixbros’s picture

Issue summary: View changes
diegors’s picture

Assigned: Unassigned » diegors
diegors’s picture

Assigned: diegors » Unassigned
gquisini’s picture

I'll try to work on this one

gquisini’s picture

Status: Active » Needs work

I 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 the loading attribute.

I believe that the automated tests will be required to validate the changes, so I will move the issue to NW.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

Title: media images set to "eager loading" display as lazy in html » Setting media field to loading="eager" doesn’t work when using the media_thumbnail field formatter
Version: 9.5.x-dev » 10.1.x-dev
Component: field system » media system
Issue summary: View changes
StatusFileSize
new51.87 KB

Just 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.

heddn’s picture

Issue tags: +Needs tests

Posted some feedback on the MR. Also could use some test coverage to make sure we don't regress here.

bbu23’s picture

Patch MR !2873 works for me on Drupal 10.0.4.

heddn’s picture

Still NW for addition of tests and the MR feedback.

heddn’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

This 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.

mherchel’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new978 bytes

Verified 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 3307409-16-TEST-ONLY-FAIL.patch, failed testing. View results

mherchel’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new20.89 KB

Test only patch failed! RTBC!

Task failed successfully

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 3307409-16-TEST-ONLY-FAIL.patch, failed testing. View results

mherchel’s picture

Status: Needs work » Reviewed & tested by the community

  • catch committed 0687f85d on 10.1.x
    Issue #3307409 by mherchel, heddn, gquisini, Phoenixbros, bbu23: Setting...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, thanks!

mherchel’s picture

yay!

@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

catch’s picture

We could but it would be nice to get 10.0 and 9.5 test runs.

mherchel’s picture

StatusFileSize
new978 bytes
new978 bytes
new2.56 KB
new2.56 KB

Makes sense!

Patches are attached. Note this is the exact same patch as the commit in #21

mherchel’s picture

Status: Fixed » Reviewed & tested by the community

We could but it would be nice to get 10.0 and 9.5 test runs.

Test runs completed. Setting to RTBC so it doesn't slip through the cracks. Thanks!

  • catch committed d3608560 on 10.0.x
    Issue #3307409 by mherchel, heddn, gquisini, Phoenixbros, bbu23: Setting...

  • catch committed 9a4c8b08 on 9.5.x
    Issue #3307409 by mherchel, heddn, gquisini, Phoenixbros, bbu23: Setting...
catch’s picture

Version: 10.1.x-dev » 9.5.x-dev

Backported to both branches, thanks!

mherchel’s picture

Status: Reviewed & tested by the community » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.