- From: Anne van Kesteren <notifications@github.com>
- Date: Wed, 08 Jul 2026 09:07:10 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/pull/1488@github.com>
replace removes child (with suppressObservers set) before inserting node. Because insert now adopts node as one of its steps, when node is already in the tree its removal from the old location — and the mutation record that removal queues — happened *after* child had already been silently removed. That gave the record a stale previousSibling and made the two records appear non-atomic.
Adopt node up front, before child is removed, so node's removal is observed while child is still present. This restores the record ordering and previousSibling that predates #754, which had removed replace's explicit adoption step without accounting for this interaction. All engines kept the pre-#754 behavior, so this aligns the standard with reality.
The related replace all algorithm intentionally keeps adopting inside insert: its only caller that can receive an already-present node is `replaceChildren()`, which postdates #754 and folds such a node into its single record.
Fixes #814.
<!--
Thank you for contributing to the DOM Standard! Please describe the change you are making and complete the checklist below if your change is not editorial.
When you submit this PR, and each time you edit this comment (including checking a checkbox through the UI!), PR Preview will run and update it. As such make any edits in one go and only after PR Preview has run.
If you think your PR is ready to land, please double-check that the build is passing and the checklist is complete before pinging.
-->
- [x] At least two implementers are interested (and none opposed):
* All engines already implement this behavior (it predates #754); this change aligns the standard with them.
- [x] [Tests](https://github.com/web-platform-tests/wpt) are written and can be reviewed and commented upon at:
* Existing coverage in dom/nodes/MutationObserver-childList.html (n52/n53) already asserts this behavior.
* https://github.com/web-platform-tests/wpt/pull/61155 adds related `replaceChildren()` coverage.
- [ ] [Implementation bugs](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) are filed:
* Chromium: …
* Gecko: …
* WebKit: …
* Deno (only for aborting and events): …
* Node.js (only for aborting and events): …
- [ ] [MDN issue](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) is filed: …
- [x] The top of this comment includes a [clear commit message](https://github.com/whatwg/meta/blob/main/COMMITTING.md) to use. <!-- If you created this PR from a single commit, Github copied its message. Otherwise, you need to add a commit message yourself. -->
(See [WHATWG Working Mode: Changes](https://whatwg.org/working-mode#changes) for more details.)
<!--
This comment and the below content is programmatically generated.
You may add a comma-separated list of anchors you'd like a
direct link to below (e.g. #idl-serializers, #idl-sequence):
Don't remove this comment or modify anything below this line.
If you don't want a preview generated for this pull request,
just replace the whole of this comment's content by "no preview"
and remove what's below.
-->
***
### :boom: Error: 403 Forbidden :boom: ###
[PR Preview](https://github.com/tobie/pr-preview#pr-preview) failed to build. _(Last tried on Jul 8, 2026, 4:06 PM UTC)_.
<details>
<summary>More</summary>
PR Preview relies on a number of web services to run. There seems to be an issue with the following one:
:rotating_light: [HTML Diff Service](http://services.w3.org/htmldiff) - The HTML Diff Service is used to create HTML diffs of the spec changes suggested in a pull request.
:link: [Related URL](https://services.w3.org/htmldiff?doc1=https%3A%2F%2Fwhatpr.org%2Fdom%2F1488%2Fc7f757c.html&doc2=https%3A%2F%2Fwhatpr.org%2Fdom%2F1488.html)
**Error output:**
```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
<head><title>HTML Diff service</title>
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/base" />
</head>
<body>
<p><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C"/></a> <a href="http://www.w3.org/2003/Editors">W3C Editors homepage</a></p>
<h1>Create Diff between HTML pages</h1>
<p style='color:#FF0000'>An error (HTTP error: 503 Service Unavailable) occured trying to get <a href='https://whatpr.org/dom/1488.html'>https://whatpr.org/dom/1488.html</a>.</p>
<form method="GET">
<p>Address of reference document: <input name="doc1" type="url" value="" style="width:100%"/></p>
<p>Address of new document: <input name="doc2" value="https://whatpr.org/dom/1488.html" style="width:100%"/></p>
<p><input type="submit" value="get Diff"/></p>
</form>
<p><strong>Tip</strong>: if the document uses the W3C convention on linking to its previous version, you can specify only the address of the new document — the previous link will be automatically detected.</p>
<h2>Diff markings</h2>
<p>This service relies on <a href="https://www.gnu.org/software/diffutils/">GNU diff</a>. The found differences are roughly marked as follow:
<ul>
<li>deleted text is shown in pink with down-arrows (as styled for a <del> element)</li>
<li>where there is replacement, it’s shown in green with bi-directional arrows,</li>
<li>where there is newly inserted text, it’s yellow with up arrows (<ins> element)</li>
</ul>
<address>
script $Revision$ of $Date$<br />
by <a href="http://www.w3.org/People/Dom/">Dominique Hazaël-Massieux</a><br />based on <a href="https://github.com/w3c/htmldiff-ui/blob/master/htmldiff.pl">Shane McCarron’ Perl script</a> wrapped in a <a href="https://github.com/w3c/htmldiff-ui/blob/master/htmldiff">Python CGI</a>
</address>
</body>
</html>
```
_This seems to be an issue with the [HTML Diff Service](http://services.w3.org/htmldiff) service. PR Preview doesn't manage this service and so has no control over it. If you've identified an issue with it, you can [report the issue to the maintainers of HTML Diff Service](https://github.com/w3c/htmldiff-ui/issues/new) directly. Please be courteous. Thank you!_
_If you don't have enough information above to solve the error by yourself or if the issue doesn't seem related to HTML Diff Service, you can [file an issue with PR Preview](https://github.com/tobie/pr-preview/issues/new?title=Unidentified%20Error&body=See%20whatwg/dom%231488.)._
</details>
You can view, comment on, or merge this pull request online at:
https://github.com/whatwg/dom/pull/1488
-- Commit Summary --
* Adopt node before removing child in replace
-- File Changes --
M dom.bs (5)
-- Patch Links --
https://github.com/whatwg/dom/pull/1488.patch
https://github.com/whatwg/dom/pull/1488.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1488
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/pull/1488@github.com>
Received on Wednesday, 8 July 2026 16:07:15 UTC