<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>300845</bug_id>
          
          <creation_ts>2025-10-15 16:22:26 -0700</creation_ts>
          <short_desc>[css-anchor-position-1] display: block to none transition doesn&apos;t work with anchor positioning</short_desc>
          <delta_ts>2025-11-04 02:17:18 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>301056</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kiet Ho">kiet.ho</reporter>
          <assigned_to name="Kiet Ho">kiet.ho</assigned_to>
          <cc>kiet.ho</cc>
    
    <cc>koivisto</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2151458</commentid>
    <comment_count>0</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2025-10-15 16:22:26 -0700</bug_when>
    <thetext>rdar://160639948</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2151459</commentid>
    <comment_count>1</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2025-10-15 16:25:39 -0700</bug_when>
    <thetext>See reduced testcase.

On the first click, &quot;Content&quot; transitions from display: none to block, and it displays at the correct location. On the second click, it transitions from display: block to none. However, when the transition is running, the content jumps to a different position, which it shouldn&apos;t. This is because left: anchor(...) fails to resolve, and it fallbacks to left: auto.

The culprit seems to be around StyleTreeResolver.cpp:793:

    auto applyAnimations = [&amp;]() -&gt; std::pair&lt;std::unique_ptr&lt;RenderStyle&gt;, OptionSet&lt;AnimationImpact&gt;&gt; {
        if (hasUnresolvedAnchorPosition)
            return { WTFMove(resolvedStyle.style), OptionSet&lt;AnimationImpact&gt; { } };

When an anchor-positioned element transitions from display: block to none:

* On the first style resolution, resolvedStyle.style-&gt;display() == none, hasUnresolvedAnchorPosition is true because anchor positioned elements are only resolved after the second resolution. Hence, we return resolvedStyle.style as the animation style, which has display: none. RenderTreeUpdater will then tear down the renderer because display: none

* On the second style resolution:
** AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout runs to match anchors for anchor-positioned element. However, since the anchor-positioned&apos;s renderer doesn&apos;t exist (previously torn down), it couldn&apos;t match any anchors.
** AnchorPositionEvaluator::evaluate is called to evaluate the anchor function, but since no anchor matches are recorded, the function can&apos;t be resolved
** When TreeResolver::createAnimatedElementUpdate runs, the transition is applied. Transition from display: block to none results in block until the end of the transition, when it switches to none. So the new style will have display: block
** RenderTreeUpdater creates a new renderer because there was no renderer (previously torn down), and display: block

The result:
* We needlessly tear down and create new renderers
* More importantly, on the second style resolution, we can&apos;t resolve anchor functions. Therefore when the transition is running, the position of the anchor-positioned element is as if the anchor functions can&apos;t be resolved

The second point results in the content jumping when the transition from display: block to none runs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2151460</commentid>
    <comment_count>2</comment_count>
      <attachid>477096</attachid>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2025-10-15 16:25:59 -0700</bug_when>
    <thetext>Created attachment 477096
Reduced testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2156217</commentid>
    <comment_count>3</comment_count>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2025-11-04 02:17:18 -0800</bug_when>
    <thetext>Dupe of 301056

*** This bug has been marked as a duplicate of bug 301056 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>477096</attachid>
            <date>2025-10-15 16:25:59 -0700</date>
            <delta_ts>2025-10-15 16:25:59 -0700</delta_ts>
            <desc>Reduced testcase</desc>
            <filename>anchor-function-transition.html</filename>
            <type>text/html</type>
            <size>730</size>
            <attacher name="Kiet Ho">kiet.ho</attacher>
            
              <data encoding="base64">PCEtLSByZGFyOi8vMTYwNjM5OTQ4IChbcm9vdF0gW0FuY2hvciBQb3NpdGlvbmluZ10gSjcxNS8y
NUUxMTY6IFRleHQgb3ZlcmxhcHMgd2hlbiBzd2l0Y2hpbmcgYmV0d2VlbiBuZXN0ZWQgc3VibWVu
dXMpIC0tPgo8IS0tIFNvdXJjZTogaHR0cHM6Ly9jb2RlcGVuLmlvL21pY2hlbGxlYmFya2VyL3Bl
bi9xQkdFVm92IC0tPgoKPHN0eWxlPgoubWVudSB7Cgl3aWR0aDogY2FsYygxMDAlIC8gMyk7Cglh
bmNob3ItbmFtZTogLS1hbmNob3I7CiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgYmxhY2s7Cn0K
Ci5zdWJtZW51IHsKICAgICAgICBkaXNwbGF5OiBub25lOwogICAgICAgIHBvc2l0aW9uOiBhYnNv
bHV0ZTsKCWxlZnQ6IGFuY2hvcigtLWFuY2hvciByaWdodCk7CgoJdHJhbnNpdGlvbjogZGlzcGxh
eSAzcyBhbGxvdy1kaXNjcmV0ZTsKfQo8L3N0eWxlPgoKPGRpdiBjbGFzcz0ibWVudSI+Cgk8YnV0
dG9uIG9uY2xpY2s9InRyYW5zaXRpb24oKSI+CgkJT3BlbgoJPC9idXR0b24+Cgo8L2Rpdj4KCjxk
aXYgY2xhc3M9InN1Ym1lbnUiIGlkPSJzdWJtZW51Ij4KCUNvbnRlbnQKPC9kaXY+CgoKPHNjcmlw
dD4KZnVuY3Rpb24gdHJhbnNpdGlvbigpIHsKICBpZiAoc3VibWVudS5zdHlsZS5kaXNwbGF5ID09
PSAiYmxvY2siKQogICAgc3VibWVudS5zdHlsZS5kaXNwbGF5ID0gIm5vbmUiOwogIGVsc2UKICAg
IHN1Ym1lbnUuc3R5bGUuZGlzcGxheSA9ICJibG9jayI7Cn0KPC9zY3JpcHQ+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>