[whatwg/dom] Let replaceChildren() replace a document's children (PR #1487)

replaceChildren() removes all of the parent's children before inserting, but "ensure pre-insert validity" still counted them. So replacing a document's children, e.g. document.replaceChildren(element), threw a "HierarchyRequestError" DOMException even though the result would be a valid document.

Generalize the childToExclude concept (added for replace()) into a list of children to exclude from the validity checks, and have replaceChildren() exclude all of the parent's children. As the child being replaced is now handled uniformly, the isReplace boolean is gone.

Fixes #1045.

- [ ] At least two implementers are interested (and none opposed):
   * …
   * …
- [x] [Tests](https://github.com/web-platform-tests/wpt) are written and can be reviewed and commented upon at:
   * https://github.com/web-platform-tests/wpt/pull/61154 <!-- If these tests are tentative, link a PR to make them non-tentative. -->
- [ ] [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: …
- [ ] 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.)

You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/dom/pull/1487

-- Commit Summary --

  * Let replaceChildren() replace a document's children

-- File Changes --

    M dom.bs (28)

-- Patch Links --

https://github.com/whatwg/dom/pull/1487.patch
https://github.com/whatwg/dom/pull/1487.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/pull/1487
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/pull/1487@github.com>

Received on Wednesday, 8 July 2026 15:21:19 UTC