(Re-)Add width / height also on fallback image

Created on 10 May 2023, over 1 year ago
Updated 9 August 2023, over 1 year ago

Follow-up issue on 📌 Apply width and height attributes to allow responsive image tag use loading="lazy" Fixed from comment #296 📌 Apply width and height attributes to allow responsive image tag use loading="lazy" Fixed :

Problem/Motivation

Google Pagespeed is complaning about missing width and height attributes on the fallback image now.

The commit contained these lines:

+    // We don't set dimensions for fallback image if rendered in picture tag.
+    // In Firefox, it results in sizing the entire picture element to the size
+    // of the fallback image, instead of the size on the source element.
+    $dimensions = responsive_image_get_image_dimensions($responsive_image_style->getFallbackImageStyle(), [
+      'width' => $variables['width'],
+      'height' => $variables['height'],
+    ],
+      $variables['uri']
+    );
+    $variables['img_element']['#width'] = $dimensions['width'];
+    $variables['img_element']['#height'] = $dimensions['height'];

In the issue summary and comment #15 I found

Firefox has open issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1694741 (linked from https://github.com/mozilla/standards-positions/issues/485)

when looking for "Firefox".
Both are closed. Might have been fixed between this issue and commen was created in 2021 and now.

Pagespeed says:

Image elements do not have explicit width and height
Set an explicit width and height on image elements to reduce layout shifts and improve CLS

for some <img loading="lazy" ... />'s within picture tags. This makes sense because if the image is lazy, it should also have width/height. And it should be the browsers job to handle the values correctly.

So should we add a follow-up to investigate on removing this exclusion?

Steps to reproduce

Proposed resolution

Remove the exclusion for fallback images as this seems to be now fixed in FF and PageSpeed complains occasionally.

Remaining tasks

  1. Check if this is really fixed in FF
  2. Remove the special handling

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.1

Component
Responsive image 

Last updated 3 days ago

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024