Skip to content

HTML insertion positional methods#12528

Open
noamr wants to merge 10 commits into
whatwg:mainfrom
noamr:positional
Open

HTML insertion positional methods#12528
noamr wants to merge 10 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.)


/dynamic-markup-insertion.html ( diff )

@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)

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

1 participant