Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 00af7a4b15fa54b9bbb20689f0fc8dc822474331
      
https://github.com/WebKit/WebKit/commit/00af7a4b15fa54b9bbb20689f0fc8dc822474331
  Author: Anne van Kesteren <[email protected]>
  Date:   2026-09-08 (Tue, 08 Sep 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/svg-img-zero-height-with-viewbox-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/svg-img-zero-height-with-viewbox.html
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/w3c-import.log
    M Source/WebCore/rendering/RenderImage.cpp
    M Source/WebCore/rendering/RenderImage.h
    M Source/WebCore/rendering/RenderReplaced.cpp
    M Source/WebCore/rendering/RenderReplaced.h

  Log Message:
  -----------
  SVG image with a height of 0 and no width is sized as if it had no natural 
dimensions
https://bugs.webkit.org/show_bug.cgi?id=323310

Reviewed by Alan Baradlay.

For an <img> whose SVG has height="0", a viewBox, and no width, layout
sized the box as if the image had no natural dimensions at all, filling
the containing block, instead of deriving a natural width of 0 from the
natural height of 0 and the natural aspect ratio. RenderReplaced
respects a specified 0 width but cannot tell a specified 0 height from
an absent one, while SVGImage::resolvedIntrinsicSize does derive it,
which is why naturalWidth and naturalHeight report 0x0 for the same
image. Chrome and Firefox report 0 as well.

299085@main added shouldRespectZeroIntrinsicWidth without a height
counterpart, so that a degenerate aspect ratio from a 0 block size falls
back to the viewBox ratio relative to an inline size, per
https://github.com/w3c/csswg-drafts/issues/6286#issuecomment-866986544.
That is correct when there is a natural width to derive the height from,
as in css/css-grid/alignment/grid-item-aspect-ratio-stretch-4.html.
Without one there is nothing to derive from and the natural height of 0
stands, so only respect it when there is no natural width.

This also explains an intermittent failure of the imported
naturalWidth-naturalHeight-width-height.html, whose three "SVG image,
with natural height of 0, and aspect ratio from viewBox" subtests
reported a width of 720 rather than 0 on some runs. With the SVG not yet
parsed when the box was laid out there was no aspect ratio yet and the
box came out 0x0; a warm memory cache made the image available up front
and produced 720. Nothing recomputed the width once the image arrived,
so whichever value the first layout produced stuck.

Test: 
imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/svg-img-zero-height-with-viewbox.html

Test upstream: https://github.com/web-platform-tests/wpt/pull/62512

Canonical link: https://commits.webkit.org/320642@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to