Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 40f2d454bc8084bbc80e188b6595dcc3d883dad2
      
https://github.com/WebKit/WebKit/commit/40f2d454bc8084bbc80e188b6595dcc3d883dad2
  Author: Alan Baradlay <[email protected]>
  Date:   2026-05-14 (Thu, 14 May 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-svg-no-intrinsic-column-001-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-svg-no-intrinsic-column-001-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-svg-no-intrinsic-column-001.html
    M Source/WebCore/rendering/RenderFlexibleBox.cpp

  Log Message:
  -----------
  [Flex] SVG image with no intrinsic dimensions collapses to height 0 in column 
flex container
https://bugs.webkit.org/show_bug.cgi?id=314774

Reviewed by Antti Koivisto.

  <div style="display: flex; flex-direction: column; width: 150px; height: 0">
    <img src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' />">
  </div>

The image should be 150x150 (the spec's "use 150px for the height" fallback for
boxes without a preferred aspect ratio). Instead it was 150x0 - the flex
algorithm took its automatic minimum size from a bogus aspect-ratio computation
that returned 0.

flexItemHasComputableAspectRatio used "intrinsicSize().height() != 0" as a
shortcut for "this item has a real aspect ratio". RenderReplaced caches a
(300, 150) fallback intrinsic for boxes with no real intrinsic dimensions, so
the check returned true even for our empty SVG. The aspect-ratio branch then
asked preferredAspectRatioAsSize() for the actual ratio, got (0, 0), computed
crossSize * (0/0) = NaN, and the LayoutUnit constructor turned NaN into 0.

Two of the three || checks in this function just repeated what
flexItemHasAspectRatio (called right above) already checks, so they were
doing nothing. The intrinsicSize().height() check was the only one that
actually mattered - and it was the broken one.

The fix replaces the unreliable intrinsicSize().height() shortcut with the
same test the math already uses: 
preferredAspectRatioAsSize().aspectRatioDouble() > 0.
This is true exactly when there is a real ratio (CSS aspect-ratio, real
intrinsic dimensions, or SVG viewBox). The same trick is already used by the
existing isSVGRootWithIntrinsicAspectRatio helper.

* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::flexItemHasComputableAspectRatio const):
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-svg-no-intrinsic-column-001{,-ref,-expected}.html:
 Added.

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



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

Reply via email to