<?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>326182</bug_id>
          
          <creation_ts>2026-10-03 00:28:23 -0700</creation_ts>
          <short_desc>moveBefore() leaves selectors that depend on the child list stale</short_desc>
          <delta_ts>2026-10-07 17:23:17 -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>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=317287</see_also>
          <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>281223</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Anne van Kesteren">annevk</reporter>
          <assigned_to name="Luke Warlow">lwarlow</assigned_to>
          <cc>lwarlow</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2258179</commentid>
    <comment_count>0</comment_count>
      <attachid>481650</attachid>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2026-10-03 00:28:23 -0700</bug_when>
    <thetext>Created attachment 481650
test

ContainerNode::moveBefore() runs no Style::ChildChangeInvalidation, for either the old parent or the new one. insertBefore(), appendChild() and removeChild() all wrap the DOM change in one. Since 315405@main, Node::movingSteps() invalidates the moved subtree. But nothing invalidates the parents or their other children, so every selector that depends on the child list keeps its old result after a move.

The attached test moves an element with moveBefore() and checks the result. With ?append it uses append() instead (and passes).

This is probably also why dom/nodes/moveBefore/focus-within.html fails &quot;:focus-within should be eventually up to date when moving to a subtree that would become inert via style&quot;. The inertness there comes from :has(button) on the new parent.

moveBefore() already builds both child changes, with makeChildChangeForMoveRemoval() and makeChildChangeForMoveInsertion(), but only passes them to childrenChanged(). Running a Style::ChildChangeInvalidation around each half of the move would fix  this, with one catch. ChildChange::isInsertion() returns false for ElementMovedInto, TextMovedInto and NonContentsChildMovedInto. ChildChangeInvalidation relies on it to choose before- or after-change invalidation, and for :empty. Other childrenChanged() overrides read isInsertion() too, so style needs its own answer for the move types rather than a change to isInsertion().

Bug 317287 is about doing less work for the moved subtree itself, which is a separate question. There is no WPT for this yet; one in dom/nodes/moveBefore/ along the lines of the attached test would cover it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2260092</commentid>
    <comment_count>1</comment_count>
    <who name="Luke Warlow">lwarlow</who>
    <bug_when>2026-10-07 07:48:29 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/76188</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2260423</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-10-07 17:22:24 -0700</bug_when>
    <thetext>Committed 323044@main (6839061acafd): &lt;https://commits.webkit.org/323044@main&gt;

Reviewed commits have been landed. Closing PR #76188 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2260424</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-10-07 17:23:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/189461850&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>481650</attachid>
            <date>2026-10-03 00:28:23 -0700</date>
            <delta_ts>2026-10-03 00:28:23 -0700</delta_ts>
            <desc>test</desc>
            <filename>movebefore-child-change-invalidation.html</filename>
            <type>text/html</type>
            <size>1953</size>
            <attacher name="Anne van Kesteren">annevk</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxzdHlsZT4KLmhhc0NoaWxkOmhhcyg+IC5tYXJrZWQpIHsgY29sb3I6
IGdyZWVuOyB9Ci5lbXB0eUNoZWNrOmVtcHR5IHsgY29sb3I6IGdyZWVuOyB9Ci5maXJzdENoZWNr
ID4gOmZpcnN0LWNoaWxkIHsgY29sb3I6IGdyZWVuOyB9Ci5udGhDaGVjayA+IDpudGgtY2hpbGQo
MikgeyBjb2xvcjogZ3JlZW47IH0KLnNpYmxpbmdDaGVjayAuYSArIC5iIHsgY29sb3I6IGdyZWVu
OyB9Cjwvc3R5bGU+CjxkaXYgaWQ9aGFzU291cmNlIGNsYXNzPWhhc0NoaWxkPjxzcGFuIGlkPWhh
c01vdmVkIGNsYXNzPW1hcmtlZD5tb3ZlZDwvc3Bhbj48L2Rpdj4KPGRpdiBpZD1oYXNEZXN0aW5h
dGlvbiBjbGFzcz1oYXNDaGlsZD48L2Rpdj4KPGRpdiBpZD1lbXB0eVNvdXJjZSBjbGFzcz1lbXB0
eUNoZWNrPjxzcGFuIGlkPWVtcHR5TW92ZWQ+bW92ZWQ8L3NwYW4+PC9kaXY+CjxkaXYgaWQ9ZW1w
dHlEZXN0aW5hdGlvbj48L2Rpdj4KPGRpdiBjbGFzcz1maXJzdENoZWNrPjxzcGFuIGlkPWZpcnN0
TW92ZWQ+Zmlyc3Q8L3NwYW4+PHNwYW4gaWQ9c2Vjb25kPnNlY29uZDwvc3Bhbj48L2Rpdj4KPGRp
diBpZD1maXJzdERlc3RpbmF0aW9uPjwvZGl2Pgo8ZGl2IGNsYXNzPW50aENoZWNrPjxzcGFuIGlk
PW50aE1vdmVkPjE8L3NwYW4+PHNwYW4+Mjwvc3Bhbj48c3BhbiBpZD10aGlyZD4zPC9zcGFuPjwv
ZGl2Pgo8ZGl2IGlkPW50aERlc3RpbmF0aW9u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