<?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>292972</bug_id>
          
          <creation_ts>2025-05-13 23:39:11 -0700</creation_ts>
          <short_desc>[css-anchor-position-1] animation + anchor-positioned element as popover cause anchor-positioned element to be repainted every style resolution</short_desc>
          <delta_ts>2025-05-19 09:45:59 -0700</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>NEW</bug_status>
          <resolution></resolution>
          
          
          <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>
          
          <blocked>291856</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Kiet Ho">kiet.ho</reporter>
          <assigned_to name="Kiet Ho">kiet.ho</assigned_to>
          <cc>fantasai.bugs</cc>
    
    <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>2116965</commentid>
    <comment_count>0</comment_count>
      <attachid>475222</attachid>
    <who name="Kiet Ho">kiet.ho</who>
    <bug_when>2025-05-13 23:39:11 -0700</bug_when>
    <thetext>Created attachment 475222
Test case

See test case. Test case has a scroll driven animation, a button that triggers a popover element that&apos;s anchor-positioned to the button. When the popover is shown, it keeps getting painted over and over again, about 1 per frame. Enable &quot;Show layer borders&quot; to see the paint counter going up and up.

Root cause: AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout() calls setNeedsLayout() once on each anchor-positioned element. setNeedsLayout() repaints the entire layer if the element is in a layer:

inline void RenderObject::setNeedsLayout(MarkingBehavior markParents)
{
    [...]
    if (hasLayer())
        setLayerNeedsFullRepaint();
}

Since anchor-positioned element is a popover, it&apos;s placed in the top layer. Hence it has a layer and the layer is forced to repaint.

Because AnchorPositionEvaluator::updateAnchorPositioningStatesAfterInterleavedLayout() is called at least once during style/layout interleaving, this guarantees the layer is repainted at least once per style resolution. When there&apos;s an animation, the style is resolved every frame, so the effect is that the layer is repainted every frame.

Ideally, we don&apos;t setNeedsLayout() on each anchor-positioned element every style resolution. It should only be called when the anchor the element depends on changes (in size or position) to re-layout the anchor-positioned element. This should be done in Style::Scope::invalidateForAnchorDependencies.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2116966</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-05-13 23:39:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/151285174&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>475222</attachid>
            <date>2025-05-13 23:39:11 -0700</date>
            <delta_ts>2025-05-13 23:39:11 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>975</size>
            <attacher name="Kiet Ho">kiet.ho</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgoKPGhlYWQ+CiAgPHN0eWxlPgogICAgQGtleWZyYW1lcyBn
cm93LXByb2dyZXNzIHsKICAgICAgZnJvbSB7CiAgICAgICAgdHJhbnNmb3JtOiBzY2FsZVgoMCk7
CiAgICAgIH0KCiAgICAgIHRvIHsKICAgICAgICB0cmFuc2Zvcm06IHNjYWxlWCgxKTsKICAgICAg
fQogICAgfQoKICAgIGZvb3Rlcjo6YWZ0ZXIgewogICAgICBjb250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