Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 75c76714a5df90935311250ebe4450fbcf94d9a2
      
https://github.com/WebKit/WebKit/commit/75c76714a5df90935311250ebe4450fbcf94d9a2
  Author: Kiet Ho <[email protected]>
  Date:   2026-09-15 (Tue, 15 Sep 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/css/css-conditional/container-queries/pseudo-elements-005-expected.txt
    M Source/WebCore/style/ContainerQueryEvaluator.cpp
    M Source/WebCore/style/ContainerQueryEvaluator.h
    M Source/WebCore/style/StyleTreeResolver.cpp

  Log Message:
  -----------
  [Re-land] [css-conditional-5] @container style queries on pseudo-element's 
host element uses old style data
rdar://186885497
https://bugs.webkit.org/show_bug.cgi?id=323646

Reviewed by Antti Koivisto.

(this was previously landed in 319186@main, then got reverted in 319568@main
for MotionMark regression)

During style resolution, new styles aren't committed to the render tree right 
away.
Instead, they're packaged into a Style::Update, and once style resolution 
completes,
it's passed to RenderTreeUpdater to update the styles in the render tree. 
@container
style queries should be evaluated against the newest style of the container 
element.
But the queries are evaluated during style resolution, when new styles aren't 
committed
to the render tree yet. Hence evaluating against the current (stale) render 
style might
lead to incorrect results.

To workaround this, ContainerQueryEvaluator has access to the Style::Update 
object,
so it gets the new style of a container element from there, and falls back to 
the render
style if a style isn't in Update. The Update object is threaded from 
TreeResolver ->
TreeResolver::Scope -> SelectorMatchingState -> ContainerQueryEvaluationState ->
used by Style::styleForContainer to get the style for style query evaluation.

However, during style resolution of an element, the timing when the Update 
object is
updated doesn't work for @container style queries affecting a pseudo-element.

1) resolve the element's style
2) resolve its pseudo-elements' styles
  2.1) @container queries are evaluated if a @container rule affects a 
pseudo-element
3) the element's and its psuedo-elements' styles are addded to the Update object

When 2.1) runs, @container style queries are evaluated against the container 
element,
which is the host. But the host's new style resolved in 1) is not added to the 
Update
object yet, since it's only done in 3) after all pseudo-elements' styles are 
resolved.
Hence ContainerQueryEvaluator will use the (stale) host's render style.

To fix this, after step 1) but before 2), we save a copy of the element's style 
in
ContainerQueryEvaluationState::hostElementStyle. Then if there are container 
style queries
on pseudo-elements of the element, they can be queried against the saved host 
element's
style. It's set using SetForScope, so it'll only be saved for the duration of
TreeResolver::resolveElement.

Test: 
imported/w3c/web-platform-tests/css/css-conditional/container-queries/pseudo-elements-005.html

* 
LayoutTests/imported/w3c/web-platform-tests/css/css-conditional/container-queries/pseudo-elements-005-expected.txt:
* Source/WebCore/style/ContainerQueryEvaluator.cpp:
(WebCore::Style::styleForContainer):
* Source/WebCore/style/ContainerQueryEvaluator.h:
* Source/WebCore/style/StyleTreeResolver.cpp:
(WebCore::Style::TreeResolver::resolveElement):

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



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

Reply via email to