Skip to content

HTML insertion positional methods#12528

Draft
noamr wants to merge 16 commits into
whatwg:mainfrom
noamr:positional
Draft

HTML insertion positional methods#12528
noamr wants to merge 16 commits into
whatwg:mainfrom
noamr:positional

Conversation

@noamr

@noamr noamr commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Add appendHTML, prependHTML, beforeHTML, afterHTML, and replaceWithHTML, alongside their *Unsafe variants.

Use 3 helper algorithms for HTML insertion (pre-insert/replace/set), and call those from the appropriate web-exposed method.

ChildNode methods fail silently when the child has no parent, like their equivalent DOM methods,
and fails with a HierarchyRequestError for an invalid parent.

Closes #10122

(See WHATWG Working Mode: Changes for more details.)


/document-lifecycle.html ( diff )
/document-sequences.html ( diff )
/dynamic-markup-insertion.html ( diff )
/infrastructure.html ( diff )
/parsing.html ( diff )
/xhtml.html ( diff )

@noamr noamr force-pushed the positional branch 2 times, most recently from 2c060c5 to 4a57e81 Compare June 8, 2026 19:35
@noamr noamr changed the title Positional HTML insertion positional methods Jun 8, 2026
@noamr noamr marked this pull request as ready for review June 8, 2026 19:55
@noamr noamr marked this pull request as draft June 9, 2026 06:46
@noamr noamr marked this pull request as ready for review June 9, 2026 15:50
brave-builds pushed a commit to brave/chromium that referenced this pull request Jun 11, 2026
Ensure a consistent order of operations for all the new HTML insertion
methods (appendHTML, prependHTML, beforeHTML, afterHTML,
replaceWithHTML)

- The trusted types createHTML test should always come first
- ChildNode methods should then ensure the parent can accept HTML, or throw
- Correctly handle <template> in all the methods
  (e.g. `template.appendHTML`, `template.content.beforeHTML`)
- Assert some edge cases in WPT (e.g. trusted types moves nodes around)

See spec PR: whatwg/html#12528

Bug: 491743369
Change-Id: I5e587ae12faad3d706e2d993bd1aa88500b3e6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7915261
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1645229}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 11, 2026
Ensure a consistent order of operations for all the new HTML insertion
methods (appendHTML, prependHTML, beforeHTML, afterHTML,
replaceWithHTML)

- The trusted types createHTML test should always come first
- ChildNode methods should then ensure the parent can accept HTML, or throw
- Correctly handle <template> in all the methods
  (e.g. `template.appendHTML`, `template.content.beforeHTML`)
- Assert some edge cases in WPT (e.g. trusted types moves nodes around)

See spec PR: whatwg/html#12528

Bug: 491743369
Change-Id: I5e587ae12faad3d706e2d993bd1aa88500b3e6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7915261
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1645229}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 11, 2026
Ensure a consistent order of operations for all the new HTML insertion
methods (appendHTML, prependHTML, beforeHTML, afterHTML,
replaceWithHTML)

- The trusted types createHTML test should always come first
- ChildNode methods should then ensure the parent can accept HTML, or throw
- Correctly handle <template> in all the methods
  (e.g. `template.appendHTML`, `template.content.beforeHTML`)
- Assert some edge cases in WPT (e.g. trusted types moves nodes around)

See spec PR: whatwg/html#12528

Bug: 491743369
Change-Id: I5e587ae12faad3d706e2d993bd1aa88500b3e6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7915261
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1645229}
@noamr

noamr commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

This should be ready for review (and for additional implementer support)

lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Jun 16, 2026
…ations, a=testonly

Automatic update from web-platform-tests
Revise HTML update methods order of operations

Ensure a consistent order of operations for all the new HTML insertion
methods (appendHTML, prependHTML, beforeHTML, afterHTML,
replaceWithHTML)

- The trusted types createHTML test should always come first
- ChildNode methods should then ensure the parent can accept HTML, or throw
- Correctly handle <template> in all the methods
  (e.g. `template.appendHTML`, `template.content.beforeHTML`)
- Assert some edge cases in WPT (e.g. trusted types moves nodes around)

See spec PR: whatwg/html#12528

Bug: 491743369
Change-Id: I5e587ae12faad3d706e2d993bd1aa88500b3e6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7915261
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1645229}

--

wpt-commits: 264d3bdd2145be1e35d8a8845b9b62b38fa8fc1c
wpt-pr: 60553
noamr and others added 15 commits June 26, 2026 14:58
Instead of inserting elements to a fake root element of a connected inert
document and then appending them to a `DocumentFragment`, we let the parser
insert the root's children straight into that `DocumentFragment`.

This is done by having an "adjusted insertion target" that the parser uses to
route insertions desined to the root of the stack directly into the fragment.

The observable behavior change is in subtle places that check for connectedness
when insertion, like radio buttons.
This is also creates an enabler that can be used later on for HTML streaming,
as the "adjusted insertion target" can be the context element instead of the
intermediate fragment.

Note that we still need some notion of the intermediate inert document,
to avoid creation time side effects like image loading and custom element
constructors to occur before sanitization.

(This resembles blink implementation, more than the current wording)

Closes whatwg#11023
@noamr noamr marked this pull request as draft July 2, 2026 09:41
@noamr

noamr commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Converting to draft because it now depends on #12624

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Improve API of insertAdjacent*() methods

2 participants