Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e0d1ff8f5bf368b81e315ff67fff6433fee07403
      
https://github.com/WebKit/WebKit/commit/e0d1ff8f5bf368b81e315ff67fff6433fee07403
  Author: Chris Dumez <[email protected]>
  Date:   2026-04-08 (Wed, 08 Apr 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/MutationObserver-document-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/customizable-select/selectedcontent-mutations-expected.txt
    M 
LayoutTests/platform/ios/imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/customizable-select/selectedcontent-mutations-expected.txt
    M Source/WebCore/dom/ContainerNode.cpp

  Log Message:
  -----------
  MutationObserver delivers childList records in wrong order when script runs 
during insertion
https://bugs.webkit.org/show_bug.cgi?id=311706

Reviewed by Ryosuke Niwa.

Mutation records for child insertions were being enqueued after any scripts
triggered by the insertion (e.g. via postConnectionSteps), because the caller's
ChildListMutationScope kept the accumulator alive across script execution.

Fix by moving the ChildListMutationScope into 
executeNodeInsertionWithScriptAssertion,
scoped to end after childrenChanged but before postConnectionSteps / 
dispatchChildInsertionEvents,
and removing the outer scopes from pure-insertion callers (appendChild, 
insertBefore, append,
prepend, insertChildrenBefore).

The scope must cover childrenChanged because HTMLSelectElement::childrenChanged 
triggers
selectOption → updateSelectedContent, which enqueues mutation records for 
<selectedcontent>.
Those records need to be enqueued before the parent's child insertion record 
(since they are
a side-effect of the insertion). If the scope ended before childrenChanged, the 
parent's
record would be flushed first, reversing the expected order.

No new tests, covered by existing WPT tests that were rebaselined. These tests
were already passing in Chrome and Firefox so this aligns our behavior with
them.

* 
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/MutationObserver-document-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/customizable-select/selectedcontent-mutations-expected.txt:
* Source/WebCore/dom/ContainerNode.cpp:
(WebCore::executeNodeInsertionWithScriptAssertion):
(WebCore::ContainerNode::insertBefore):
(WebCore::ContainerNode::appendChildWithoutPreInsertionValidityCheck):
(WebCore::ContainerNode::insertChildrenBeforeWithoutPreInsertionValidityCheck):
(WebCore::ContainerNode::append):
(WebCore::ContainerNode::prepend):

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



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

Reply via email to