[wp-trac] [WordPress Trac] #50367: Avoid layout shifting due to images not having dimension attributes

WordPress Trac noreply at wordpress.org
Thu Jun 25 21:08:32 UTC 2020


#50367: Avoid layout shifting due to images not having dimension attributes
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  flixos90
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  5.5
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  needs-unit-tests needs-patch needs-  |     Focuses:
  testing                                        |
-------------------------------------------------+-------------------------

Comment (by flixos90):

 Replying to [comment:12 azaozz]:
 > There seems to be a bug with this patch when an img tag has either
 `width` or `height` set (but not both).

 I was considering this when working on the patch, however didn't bother
 adding it as part of this, since this bit was already broken before. For
 the existing `srcset` and `sizes` logic, the code would always rely on the
 actual file dimensions if only one of the two was present - in other
 words, providing just one of the two attributes is not supported by core
 at the moment.

 I'm definitely for fixing this - it's not really caused by this ticket,
 but we can follow up on it here since it's definitely related
 functionality. I think what we should do here is change the condition `if
 ( ! $width || ! $height ) {` to `if ( ! $width && ! $height ) {`; and if
 only one of the two is present, return the original tag because there is
 no way for us to make an educated guess about `srcset` and `sizes` either,
 at least not with the current functionality.

 > Looking further, there doesn't seem to be a way for a plugin or a theme
 to disable auto-adding of width and height attributes to img tags. Perhaps
 at least a `true/false` filter would be good? Or maybe filter the
 `image_hwstring()` value.

 I'd question the need for this, what would be the use-case for that? In
 what circumstance would not having width and height attributes be a good
 thing? Having them shouldn't cause any issues except for themes with bad
 CSS (e.g. missing `height:auto` when it modifies image width), but I don't
 think we should cater for that, since this is clearly not recommended, and
 those themes would have been broken for a long time.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50367#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list