
Follow-up issue on #3192234: Apply width and height attributes to allow responsive image tag use loading="lazy" from comment #296:
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
- Check if this is really fixed in FF
- Remove the special handling
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#15 | codepen-width-height-firefox-113.0.1 (64-Bit).png | 38.39 KB | anybody |
#13 | 3359421-13.patch | 2 KB | grevil |
#8 | 3359421-8.patch | 2 KB | anybody |
Issue fork drupal-3359421
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
anybodyIn #228 you can see the code before the FF exclusion was added:
Comment #4
anybodyOk, let's see if I got it right. First had to understand, that the block just has to be moved below the if-clauses, but not totally sure yet it's correct.
Comment #5
anybodyComment #6
anybodyComment #7
anybodyJust tried this in dev in Firefox on some of our projects, where it would be helpful and it works as expected so far!
Without the patch, width / height are gone. With this patch, they're there and output if still fine in FF.
But definitely needs manual testing on FF and confirmation that this is 100% working as expected. Not just in my cases.
Comment #8
anybodyHere's the diff as static patch.
Comment #10
tfranz CreditAttribution: tfranz as a volunteer commentedThank you for the patch!
I can confirm the missing values in Drupal 10.0.9. With this (and other patches from this issue) it works: Width and Height are back again.
My patches:
Comment #11
anybodyManual testing works perfectly! Now we should finish the automated tests and try to get this in before 10.1!
Comment #13
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedRebased, as the MR did not apply on 10.1.x anymore. Attached the changes as a temporary patch.
Comment #14
heddnRe-categorizing as a bug report. Was the manual testing from #3192234-246: Apply width and height attributes to allow responsive image tag use loading="lazy" re-performed against FF?
See https://codepen.io/heddn/pen/LYmKway
Comment #15
anybodySorry @heddn I tested the patch, but didn't explicitly retest the Firefox behavior.
Here's a screenshot of your codepen test:

with Firefox 113.0.1 (64-Bit) on Windows 11 and browser width of 1700px the image width / height rendered is: 800x300
Comment #16
heddnLooks like it is no longer an issue. Yeah! Let's get the tests fixed to back this up.
Comment #18
anybodySwitching back to 10.1.x as this is a bugfix.
The test-fixes I tried didn't seem to be correct, taking a new approach with @Grevil today to push this forward.
Comment #19
klemendev CreditAttribution: klemendev as a volunteer and at Pylo commentedThis indeed should target 10.1.x, preferably fist release or the change to this will break CLS scoring for responsive images
Comment #20
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedComment #21
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commented1 Tests still fails, the others seem unrelated.
Comment #22
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedComment #23
anybody@Grevil: Yeah we have to be careful, as there are failing tests in core 10.1.x-dev currently. So yes, surely unrelated if not from this module!
Comment #24
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedNice, tests pass now! (The 2 remaining failing tests are unrelated)
Comment #25
anybody@heddn would you be so kind to review this perhaps? Hopefully the 10.1.x failing tests will be solved upstream soon, so we can trigger a retest with true results and mark this RTBC.
Comment #27
anybodyTests are green now :) (dev core has been fixed)
Comment #28
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedI agree with @Anybody, I don't think we need to remove the alt and loading attribute.
Comment #29
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedRTBC'ing this.
Comment #30
catchCommitted/pushed to 11.x and cherry-picked to 10.1.x, thanks!
Comment #33
catchComment #34
catchLinked this issue from the existing CR at https://www.drupal.org/node/3279032
Comment #35
anybodyFunny, the issue status shows as RTBC, while the comments say "Fixed". What's that? :D
Trying to re-set this fixed.
Thanks @catch!
Comment #36
heddnSo glad to see this fixed before 10.1.0. Thanks everyone.
Comment #37
klemendev CreditAttribution: klemendev as a volunteer and at Pylo commentedIndeed really nice to see this in 10.1.0. This release will be awesome, thanks to all involved!
Comment #38
grevil CreditAttribution: grevil as a volunteer and at DROWL.de commentedGreat, thx @catch!
Comment #40
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedI believe this commit has resulted in undefined array key errors for responsive_image themeing that don't contain a width or a height. At the very top we do this:
And now we always do
Whereas previously we only did that if there was a single source which was probably almost never.
Upgrading to 10.1 has started throwing
Comment #41
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedLooks like reverting this commit locally produces the same error so the error was introduced in #3192234: Apply width and height attributes to allow responsive image tag use loading="lazy" rolling back to 10.0 doesn't have this issue.
Comment #42
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedOpened #3375721: Undefined array key errors for responsive_image themeing without width or height also found #3375638: Undefined array key "height" and "width" when using "Responsive Background Image" formatter so other people are experiencing it.
Comment #43
heddnThe changes here seem to have introduced #3377420: Responsive image width/height values are not used from fallback image style. Testing over there is welcome.