Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 07cd6d72a12e3523c4e57524dedbb0b6da82f3b7
      
https://github.com/WebKit/WebKit/commit/07cd6d72a12e3523c4e57524dedbb0b6da82f3b7
  Author: Alan Baradlay <[email protected]>
  Date:   2026-05-13 (Wed, 13 May 2026)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001.html
    M Source/WebCore/rendering/RenderBox.cpp
    M Source/WebCore/rendering/RenderBox.h
    M Source/WebCore/rendering/RenderFlexibleBox.cpp

  Log Message:
  -----------
  Flex item with aspect-ratio keeps stale height after container resize
https://bugs.webkit.org/show_bug.cgi?id=265243
<rdar://problem/118926827>

Reviewed by Antti Koivisto.

  <div style="display: flex; width: 100%">
    <div style="width: 100%; aspect-ratio: 1/1">
      <img style="width: 100%; height: 100%">
    </div>
  </div>

After resizing the container (e.g. viewport resize or script changing width),
the wrapper div keeps its old height instead of updating to match the new width
via aspect-ratio. A reload fixes it.

The flex stretch algorithm caches each item's "intrinsic content height" so it
can restore it after stretch relayout (since stretch changes the height and
would contaminate the intrinsic value). The problem: for items with 
aspect-ratio,
this cache was never invalidated - the guard in 
cacheIntrinsicContentLogicalHeightForFlexItem
correctly prevented the normal layout path from caching (because the height
depends on the width and changes on resize), but applyStretchAlignmentToFlexItem
bypassed that guard and wrote to the cache directly. On subsequent layouts, the
stale cached value was used to determine the flex line cross size, which then
stretched the item back to the old height.

The fix: extract shouldCacheIntrinsicContentLogicalHeightForFlexItem() so both
code paths share the same caching policy. Items with aspect-ratio are excluded
from caching because their content height is always derivable from their current
width - no preservation needed.

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001-expected.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001-ref.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-flexbox/flex-aspect-ratio-resize-001.html:
 Added.
* Source/WebCore/rendering/RenderBox.cpp:
(WebCore::RenderBox::shouldCacheIntrinsicContentLogicalHeightForFlexItem const):
(WebCore::RenderBox::cacheIntrinsicContentLogicalHeightForFlexItem const):
* Source/WebCore/rendering/RenderBox.h:
* Source/WebCore/rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::applyStretchAlignmentToFlexItem):

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



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

Reply via email to