Skip to content

Un-tentative streamHTML tests - #61748

Merged
zcorpan merged 10 commits into
masterfrom
noamr/untent-stream
Nov 5, 2026
Merged

zcorpan merged 10 commits into
masterfrom
noamr/untent-stream

Conversation

@noamr

@noamr noamr commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Un-tentative the streamHTML() family of tests, now that whatwg/html#12758 is landing:

  • Move everything out of domparsing/tentative/ into domparsing/, and the streamAppendHTMLUnsafe() + <template for> tests out of html/dom/partial-updates/tentative/ into html/semantics/scripting-1/the-template-element/template-for/, pointing the help links at https://html.spec.whatwg.org/#html-streaming-methods (and #attr-template-for), and fold the streaming rules into the parent WEB_FEATURES.yml files.
  • Add the extra coverage from https://crrev.com/c/8500565 that hasn't already landed via other Chromium exports (Trusted Types violation reporting in enforced and report-only modes, chunk boundaries / foster parenting / quirks mode, custom element reaction ordering, ownerDocument and stream realm, <noscript> inside template contents, removed <img> resource fetches, positional methods on nodes without a parent).
  • Cover streamReplaceWithHTML(Unsafe) in the Trusted Types streaming tests that were missing it.
  • Add coverage for additional spec requirements:
    • <html> element handling (streamAppend/PrependHTML(Unsafe) on <html> and positional methods on <head>/<body> throwing HierarchyRequestError; streamHTML(Unsafe) on <html> replacing/implying <head> and <body>).
    • Live document interactions (document.write() implying document.open(), document.open()/close() not affecting the stream's parser, mid-stream adoption into another document, and moving a streamed <script> before its end tag).
    • Script & stylesheet blocking semantics (close() waiting for pending parser-blocking scripts while not waiting for external defer or non-async module scripts, abort() unblocking blocking="render" defer scripts, stylesheets not blocking streamed scripts, re-entrant abort()/write()/close(), and SVG <script> with runScripts).
    • Sanitizer comments option (including comments split across chunks) and <form> in replaceWithChildrenElements/removeElements not becoming the form owner.
    • Top-level <template shadowrootmode> inserted as a plain <template>, null referenceChild captured at call time, Uint8Array chunk stringification, and exception ordering (Trusted Types TypeError vs. NotSupportedError vs. HierarchyRequestError vs. sanitizer config validation).

@zcorpan

zcorpan commented Aug 11, 2026

Copy link
Copy Markdown
Member

Should this be remove-internal?

@noamr
noamr force-pushed the noamr/untent-stream branch from 7997f11 to 608fd49 Compare August 12, 2026 09:22
@noamr
noamr requested a review from a team as a code owner August 12, 2026 09:22
@noamr

noamr commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

wpt/domparsing/stream-html-with-declarative-shadow-root.html

Fixed

LunaStev pushed a commit to wavefnd-labs/blink that referenced this pull request Oct 27, 2026
Align HTMLStream's abort algorithm with "abort a fragment parser" in the
spec (whatwg/html#12758): if the parser is running when the
stream is aborted, the abort is deferred until the current run returns,
so the rest of the current chunk is still parsed and the stack of open
elements is not popped in the middle of inserting a node.

While a write() is in flight, the WritableStream already queues abort()
behind it. But after a parser-blocking external script, the parser
resumes from a task with no write in flight, so abort() called from a
streamed inline script or a custom element reaction reached
HTMLSink::abort synchronously, which called StopParsing() and Detach()
while PumpTokenizer() was on the stack and dropped the rest of the
chunk.

HTMLDocumentParser::AbortFragmentParser() records the request while a
pump session is active and PumpTokenizerIfPossible() performs the abort
once the outermost pump returns. Outside a pump the behavior is
unchanged.

Adds external/wpt/domparsing/stream-html-reentrancy.html (and its
resources/slow.js dependency) from web-platform-tests/wpt#61748 at its
final, non-tentative path.

[email protected]

Bug: 573252239, 491743369
Change-Id: I9569555cbae7f5be0ca91b3b8ede5b1198a7ad66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8579128
Commit-Queue: Noam Rosenthal <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1721059}
LunaStev pushed a commit to wavefnd-labs/blink that referenced this pull request Oct 27, 2026
… html element

Align the HTML insertion and streaming methods with the WHATWG HTML spec
("filter and pre-insert HTML", "filter and replace with HTML", and
whatwg/html#12758 for the streaming methods):

- appendHTML{Unsafe}, prependHTML{Unsafe}, streamAppendHTML{Unsafe}
  and streamPrependHTML{Unsafe} throw a "HierarchyRequestError"
  DOMException when the target is an html element.
- beforeHTML{Unsafe}, afterHTML{Unsafe}, replaceWithHTML{Unsafe}
  and their stream* counterparts throw the same exception when the
  parent is an html element.

Parsing a fragment with an html context element always produces head and
body elements, which is only suitable when replacing all children, so
setHTML{Unsafe}() and streamHTML{Unsafe}() on the html element remain
allowed.

The check, ContainerNode::CheckValidParentForPartialInsertion(), runs
after the Trusted Types compliance check and before the fragment parser
is created, so that it takes precedence over sanitizer config validation
and over removing the node for (stream)replaceWithHTML().

Adds external/wpt/domparsing/tentative/stream-html-element.html from
web-platform-tests/wpt#61748 (tentative until the streaming spec PR
lands), and html-insertion-methods-html-element.html for the
non-streaming methods.

Bug: 573276742, 491743369
Change-Id: If6caf8060b254f5f1d9ad8c0f716b3a503d3066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8576898
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Noam Rosenthal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1721116}
Un-tentative the `streamHTML()` family of tests, now that whatwg/html#12758 is landing:

- Move everything out of `domparsing/tentative/` into `domparsing/`, and the `streamAppendHTMLUnsafe()` + `<template for>` tests out of `html/dom/partial-updates/tentative/` into `html/semantics/scripting-1/the-template-element/template-for/`, pointing the help links at https://html.spec.whatwg.org/#html-streaming-methods (and `#attr-template-for`), and fold the streaming rules into the parent `WEB_FEATURES.yml` files.
- Add the extra coverage from https://crrev.com/c/8500565 that hasn't already landed via other Chromium exports (Trusted Types violation reporting in enforced and report-only modes, chunk boundaries / foster parenting / quirks mode, custom element reaction ordering, `ownerDocument` and stream realm, `<noscript>` inside template contents, removed `<img>` resource fetches, positional methods on nodes without a parent).
- Cover `streamReplaceWithHTML(Unsafe)` in the Trusted Types streaming tests that were missing it.
- Add coverage for additional spec requirements:
  - `<html>` element handling (`streamAppend/PrependHTML(Unsafe)` on `<html>` and positional methods on `<head>`/`<body>` throwing `HierarchyRequestError`; `streamHTML(Unsafe)` on `<html>` replacing/implying `<head>` and `<body>`).
  - Live document interactions (`document.write()` implying `document.open()`, `document.open()`/`close()` not affecting the stream's parser, mid-stream adoption into another document, and moving a streamed `<script>` before its end tag).
  - Script & stylesheet blocking semantics (`close()` waiting for pending parser-blocking scripts while not waiting for external `defer` or non-`async` module scripts, `abort()` unblocking `blocking="render"` defer scripts, stylesheets not blocking streamed scripts, re-entrant `abort()`/`write()`/`close()`, and SVG `<script>` with `runScripts`).
  - Sanitizer `comments` option (including comments split across chunks) and `<form>` in `replaceWithChildrenElements`/`removeElements` not becoming the form owner.
  - Top-level `<template shadowrootmode>` inserted as a plain `<template>`, null `referenceChild` captured at call time, `Uint8Array` chunk stringification, and exception ordering (Trusted Types `TypeError` vs. `NotSupportedError` vs. `HierarchyRequestError` vs. sanitizer config validation).
noamr added a commit to whatwg/html that referenced this pull request Nov 3, 2026
Introduce safe and unsafe streaming HTML parsing and insertion methods returning a `WritableStream`:
* `Element` & `ShadowRoot`: `streamHTML()`, `streamHTMLUnsafe()`, `streamAppendHTML()`, `streamAppendHTMLUnsafe()`, `streamPrependHTML()`, and `streamPrependHTMLUnsafe()`
* `NonDocumentTypeChildNode`: `streamBeforeHTML()`, `streamBeforeHTMLUnsafe()`, `streamAfterHTML()`, `streamAfterHTMLUnsafe()`, `streamReplaceWithHTML()`, and `streamReplaceWithHTMLUnsafe()`

Key behaviors and parser updates:
* **Stream operations**: `writeAlgorithm` and `closeAlgorithm` convert chunks to `DOMString`, append chunks (or an explicit `"EOF"` character on close) to the parser's input stream, and run the fragment parser. `closeAlgorithm` waits for any pending parser-blocking scripts via `fragment parser close promise`. `abortAlgorithm` aborts the fragment parser (deferring via `fragment parser abort requested` if currently running), marks open `script` elements on the stack as already started, and unblocks rendering on pending scripts.
* **Displaced reference child**: If `referenceChild` is no longer a child of `target` when a node would be inserted before it or when another chunk is written, `invalid reference child steps` error the stream (and reject `fragment parser close promise` if closing) with a `"HierarchyRequestError"` `DOMException` and abort the fragment parser. Elements that would be inserted before a displaced `referenceChild` are created in the `appropriate template contents owner document` with a null custom element registry and dropped, and the adoption agency algorithm skips removing `lastNode`.
* **Validation, Trusted Types & DOM mutations**: Target validation (throwing `"NotSupportedError"` for HTML/SVG `script` context elements, or `"HierarchyRequestError"` for `html` targets or invalid `parent for HTML streaming`), `HTMLTemplateElement` redirection to `template contents`, and Trusted Types / `SanitizerConfig` validation occur synchronously before returning the stream or mutating the DOM.
* **Scripts, custom elements & fragment parsing**:
  - Extracts `initialize an HTML fragment parser`. When `runScripts` is true, `script target document` is `context`'s node document; otherwise it is the temporary inert document.
  - Parser-blocking, `defer`, `async`, and module scripts follow normal HTML parser pausing and execution order.
  - Custom element upgrades/callbacks when inserting into a connected target run before any subsequent `script` via a dedicated element queue; other reactions when streaming HTML use the backup element queue.
  - The speculative HTML parser is not started in the fragment case. Speculative fetches from the fragment parser are still allowed, except when sanitizing or for elements that will be dropped. *The end* (`stops parsing`) returns early for fragment parsers.
  - Elements whose intended parent is the fragment root `html` element are created directly in the target's (or fragment's) node document.
  - SVG `script` elements are only processed when the parser's `script target document` is not the parser's `Document` and the `script` element is connected (which also applies to document parsing when an ancestor of an SVG `script` was disconnected before `</script>`).
  - Elements removed or replaced with their children by the sanitizer are created in the `appropriate template contents owner document` with a null custom element registry and not inserted into the DOM.

Note: Pre-existing adoption agency algorithm edge cases (#13093) are out of scope for this PR.

Closes #2142.

Tests: web-platform-tests/wpt#61748.
@noamr
noamr force-pushed the noamr/untent-stream branch from 00abb31 to e6e8fd7 Compare November 3, 2026 08:48
noamr added 5 commits November 3, 2026 09:00
…tests

The tests asserting that deferred and module scripts don't run after an abort (or after close() rejects due to a displaced reference child) waited a fixed 0 ms / 50 ms, which data: script fetches can outlast, so an engine that wrongly keeps the scripts could still pass. Wait for defer/module scripts in a freshly streamed and closed control target instead.
Also link the HTML fragment parsing algorithm, since the file covers setHTML() and friends too.
Assert the exact error thrown by createParserOptions is rethrown, drop a stale comment, and fix indentation.
The try/assert_unreached/catch pattern caught its own AssertionError when nothing threw, producing a misleading failure message.
@annevk

annevk commented Nov 3, 2026

Copy link
Copy Markdown
Member
AI feedback

Reviewed at 237a8db, alongside my comment on whatwg/html#12758.

Blockers

  • domparsing/stream-html-reentrancy.html L404 asserts #patched.textContent === "Old", which no implementation that follows the spec can pass. This is in the subtest "abort() from a foster-parented custom element reaction in table text prevents reprocessing </template>" (L371–L407).
    • <template for="m"> runs prepare content patching when its start tag is processed, which removes "Old" right away. Chromium does the same: Patch::Prepare is called from ProcessTemplateStartTag.
    • <b><a is=…>1</b><table> is then streamed into #patched before the abort at </template>.
    • So the expected end state is <?start>, <b><a>1</a></b>, the empty reconstructed <a>, an empty <table>, and <?end>, with textContent "1".
    • I couldn't run Chrome. Going by the earlier reviews, though, Canary runs the reconstructed element's connectedCallback after parsing, so it fails the marker assertion before reaching this one. That may be why this went unnoticed.
    • Consider asserting "1" (or the child list), and double-checking the other abort subtests against the spec rather than against Chrome's results.
    • If the intent is that an aborted patch keeps the old content, that's a spec change; I raised it on the HTML PR.

@noamr

noamr commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

AI review

Thanks, fixed in b414768 (spec side in whatwg/html@a62174f9b):

  • stream-html-reentrancy.html L404. The test now matches the spec: prepare content patching removes "Old" at the start tag. The subtest asserts that #patched's children are <?start>, B, A, TABLE, <?end>, with textContent "1", and is renamed to "…in table text keeps patch markers at </template>". We kept the spec behavior rather than buffering the patch.
  • Other abort subtests. I checked them against the spec rather than Chrome's results, and they match:
    • inline script after a parser-blocking script: the flag stops tokenization after </script>;
    • mutation observer at the </script> microtask checkpoint: abort a fragment parser marks scripts on the stack as already started;
    • reconstructed formatting elements: the insertion helpers and create an element for a token check the flag;
    • <body> reprocessed from table text: the body attribute merge checks the flag.
  • New tests, following the HTML PR changes:
    • stream-html-defer-async-script.html: a trailing < flushed by close() after the reference child is removed rejects close(), and the streamed defer script doesn't run (the end check).
    • stream-html-sanitizer.html: the adoption agency algorithm doesn't insert into a Document that has a document element (the example from the HTML PR review).

Chrome Canary fails all three of these subtests. The two new ones are spec behavior Chrome doesn't implement yet. The patch-marker subtest fails at the earlier connectedCallback assertion.

@annevk

annevk commented Nov 3, 2026

Copy link
Copy Markdown
Member
AI feedback

Re-reviewed at b414768, following up on my comment above. The "Old" fix and both new tests match the spec; I traced each. The the end test fails exactly when that check is missing, and the adoption agency test covers the reachable Document case.

Blockers

  • stream-insertion-logic.html L543–L578 ("ref_node displacement during table-text foster parenting…") expects the write to reject, but by the spec it resolves. I missed this in my last pass.
    • When the table text is flushed, the first character reconstructs the <a>. Because the table was removed, that <a> is foster parented through the root, before ref_node, and its connectedCallback removes ref_node.
    • The reconstructed <a> is now the current node, so " x" goes into it rather than through the root. Nothing else is inserted before ref_node, so the displacement is never detected in this write.
    • The reprocessed <template for> then goes into the <a> too. Its patch scope is the <a>, which has no markers.
    • As with the old "Old" assertion, no engine gets far enough to show this, because Chrome runs the reconstructed element's connectedCallback late.
    • One fix: leave out the formatting element to reconstruct, and remove ref_node together with the table from the inline script. The first foster-parented character then goes through the root and hits the displaced reference child.

Suggestions

  • No test currently fails without the template start-tag check that Add streaming HTML insertion methods whatwg/html#12758 kept for the table-text reprocess. The reprocessed template's scope never contains markers: here it's the reconstructed <a>, and in the L520–L540 subtest the displaced-ref check in the for branch stops it first. Combined with the fix above, putting the markers inside the table makes the check observable:

    // ref_node.streamBeforeHTMLUnsafe({runScripts: true}); detach() removes the table (kept in a variable) and ref_node
    '<table><?start name="m"?><tbody id="old"></tbody><?end?><script>detach()</script> x<template for="m"></template>'

    The write rejects either way. Without the check, the reprocessed <template for> patches the table and removes #old.

Nits

  • Two subtest names still describe the removed table-text check:

    These tokens are now reprocessed, and it's the template and body checks that stop them. Consider renaming them, as you did with "…keeps patch markers at </template>".

@noamr

noamr commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Addressed:

  • 5c1bf0d: Rewrote the table-text ref_node displacement <template for> test in domparsing/stream-insertion-logic.html without an active formatting element, detaching both the <table> (with <?start name="m"?><tbody id="old"></tbody><?end?> inside it) and ref_node from the inline script so " x" hits the displaced reference child at the root and the <template> start-tag fragment parser abort requested check keeps <template for="m"> from patching the detached table. Also updated its subtest title (…without applying <template for>).
  • 2fff823: Renamed the <body> attribute subtest in domparsing/stream-html-reentrancy.html to …does not merge <body> attributes.
  • 989d9ee: Used parent.prepend(ref_node) in the preceding <template for> after ref_node displacement subtest so ref_node (rather than <?start name="m"?>) is parent.firstChild for streamPrependHTMLUnsafe.

lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 4, 2026
…t parser is running, a=testonly

Automatic update from web-platform-tests
Defer HTMLStream abort while the fragment parser is running

Align HTMLStream's abort algorithm with "abort a fragment parser" in the
spec (whatwg/html#12758): if the parser is running when the
stream is aborted, the abort is deferred until the current run returns,
so the rest of the current chunk is still parsed and the stack of open
elements is not popped in the middle of inserting a node.

While a write() is in flight, the WritableStream already queues abort()
behind it. But after a parser-blocking external script, the parser
resumes from a task with no write in flight, so abort() called from a
streamed inline script or a custom element reaction reached
HTMLSink::abort synchronously, which called StopParsing() and Detach()
while PumpTokenizer() was on the stack and dropped the rest of the
chunk.

HTMLDocumentParser::AbortFragmentParser() records the request while a
pump session is active and PumpTokenizerIfPossible() performs the abort
once the outermost pump returns. Outside a pump the behavior is
unchanged.

Adds external/wpt/domparsing/stream-html-reentrancy.html (and its
resources/slow.js dependency) from web-platform-tests/wpt#61748 at its
final, non-tentative path.

[email protected]

Bug: 573252239, 491743369
Change-Id: I9569555cbae7f5be0ca91b3b8ede5b1198a7ad66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8579128
Commit-Queue: Noam Rosenthal <[email protected]>
Reviewed-by: Mason Freed <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1721059}

--

wpt-commits: 286b7995a5a3028cee705b5e5f67b0a960dafd44
wpt-pr: 63795
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Nov 4, 2026
…tial insertion methods on the html element, a=testonly

Automatic update from web-platform-tests
Throw HierarchyRequestError for HTML partial insertion methods on the html element

Align the HTML insertion and streaming methods with the WHATWG HTML spec
("filter and pre-insert HTML", "filter and replace with HTML", and
whatwg/html#12758 for the streaming methods):

- appendHTML{Unsafe}, prependHTML{Unsafe}, streamAppendHTML{Unsafe}
  and streamPrependHTML{Unsafe} throw a "HierarchyRequestError"
  DOMException when the target is an html element.
- beforeHTML{Unsafe}, afterHTML{Unsafe}, replaceWithHTML{Unsafe}
  and their stream* counterparts throw the same exception when the
  parent is an html element.

Parsing a fragment with an html context element always produces head and
body elements, which is only suitable when replacing all children, so
setHTML{Unsafe}() and streamHTML{Unsafe}() on the html element remain
allowed.

The check, ContainerNode::CheckValidParentForPartialInsertion(), runs
after the Trusted Types compliance check and before the fragment parser
is created, so that it takes precedence over sanitizer config validation
and over removing the node for (stream)replaceWithHTML().

Adds external/wpt/domparsing/tentative/stream-html-element.html from
web-platform-tests/wpt#61748 (tentative until the streaming spec PR
lands), and html-insertion-methods-html-element.html for the
non-streaming methods.

Bug: 573276742, 491743369
Change-Id: If6caf8060b254f5f1d9ad8c0f716b3a503d3066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8576898
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Noam Rosenthal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1721116}

--

wpt-commits: a15a3144858f9e81c11abf28858be4cd2a64e80e
wpt-pr: 63805
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Nov 4, 2026
…t parser is running, a=testonly

Automatic update from web-platform-tests
Defer HTMLStream abort while the fragment parser is running

Align HTMLStream's abort algorithm with "abort a fragment parser" in the
spec (whatwg/html#12758): if the parser is running when the
stream is aborted, the abort is deferred until the current run returns,
so the rest of the current chunk is still parsed and the stack of open
elements is not popped in the middle of inserting a node.

While a write() is in flight, the WritableStream already queues abort()
behind it. But after a parser-blocking external script, the parser
resumes from a task with no write in flight, so abort() called from a
streamed inline script or a custom element reaction reached
HTMLSink::abort synchronously, which called StopParsing() and Detach()
while PumpTokenizer() was on the stack and dropped the rest of the
chunk.

HTMLDocumentParser::AbortFragmentParser() records the request while a
pump session is active and PumpTokenizerIfPossible() performs the abort
once the outermost pump returns. Outside a pump the behavior is
unchanged.

Adds external/wpt/domparsing/stream-html-reentrancy.html (and its
resources/slow.js dependency) from web-platform-tests/wpt#61748 at its
final, non-tentative path.

R=masonfchromium.org

Bug: 573252239, 491743369
Change-Id: I9569555cbae7f5be0ca91b3b8ede5b1198a7ad66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8579128
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Reviewed-by: Mason Freed <masonfchromium.org>
Cr-Commit-Position: refs/heads/main{#1721059}

--

wpt-commits: 286b7995a5a3028cee705b5e5f67b0a960dafd44
wpt-pr: 63795

UltraBlame original commit: 017536f25b6eb1008458f9efd92984d7a12b8824
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Nov 4, 2026
…tial insertion methods on the html element, a=testonly

Automatic update from web-platform-tests
Throw HierarchyRequestError for HTML partial insertion methods on the html element

Align the HTML insertion and streaming methods with the WHATWG HTML spec
("filter and pre-insert HTML", "filter and replace with HTML", and
whatwg/html#12758 for the streaming methods):

- appendHTML{Unsafe}, prependHTML{Unsafe}, streamAppendHTML{Unsafe}
  and streamPrependHTML{Unsafe} throw a "HierarchyRequestError"
  DOMException when the target is an html element.
- beforeHTML{Unsafe}, afterHTML{Unsafe}, replaceWithHTML{Unsafe}
  and their stream* counterparts throw the same exception when the
  parent is an html element.

Parsing a fragment with an html context element always produces head and
body elements, which is only suitable when replacing all children, so
setHTML{Unsafe}() and streamHTML{Unsafe}() on the html element remain
allowed.

The check, ContainerNode::CheckValidParentForPartialInsertion(), runs
after the Trusted Types compliance check and before the fragment parser
is created, so that it takes precedence over sanitizer config validation
and over removing the node for (stream)replaceWithHTML().

Adds external/wpt/domparsing/tentative/stream-html-element.html from
web-platform-tests/wpt#61748 (tentative until the streaming spec PR
lands), and html-insertion-methods-html-element.html for the
non-streaming methods.

Bug: 573276742, 491743369
Change-Id: If6caf8060b254f5f1d9ad8c0f716b3a503d3066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8576898
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1721116}

--

wpt-commits: a15a3144858f9e81c11abf28858be4cd2a64e80e
wpt-pr: 63805

UltraBlame original commit: fb9ed559b2ed948685d1f675f6b4cb3437bdd930
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Nov 4, 2026
…t parser is running, a=testonly

Automatic update from web-platform-tests
Defer HTMLStream abort while the fragment parser is running

Align HTMLStream's abort algorithm with "abort a fragment parser" in the
spec (whatwg/html#12758): if the parser is running when the
stream is aborted, the abort is deferred until the current run returns,
so the rest of the current chunk is still parsed and the stack of open
elements is not popped in the middle of inserting a node.

While a write() is in flight, the WritableStream already queues abort()
behind it. But after a parser-blocking external script, the parser
resumes from a task with no write in flight, so abort() called from a
streamed inline script or a custom element reaction reached
HTMLSink::abort synchronously, which called StopParsing() and Detach()
while PumpTokenizer() was on the stack and dropped the rest of the
chunk.

HTMLDocumentParser::AbortFragmentParser() records the request while a
pump session is active and PumpTokenizerIfPossible() performs the abort
once the outermost pump returns. Outside a pump the behavior is
unchanged.

Adds external/wpt/domparsing/stream-html-reentrancy.html (and its
resources/slow.js dependency) from web-platform-tests/wpt#61748 at its
final, non-tentative path.

R=masonfchromium.org

Bug: 573252239, 491743369
Change-Id: I9569555cbae7f5be0ca91b3b8ede5b1198a7ad66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8579128
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Reviewed-by: Mason Freed <masonfchromium.org>
Cr-Commit-Position: refs/heads/main{#1721059}

--

wpt-commits: 286b7995a5a3028cee705b5e5f67b0a960dafd44
wpt-pr: 63795

UltraBlame original commit: 017536f25b6eb1008458f9efd92984d7a12b8824
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Nov 4, 2026
…tial insertion methods on the html element, a=testonly

Automatic update from web-platform-tests
Throw HierarchyRequestError for HTML partial insertion methods on the html element

Align the HTML insertion and streaming methods with the WHATWG HTML spec
("filter and pre-insert HTML", "filter and replace with HTML", and
whatwg/html#12758 for the streaming methods):

- appendHTML{Unsafe}, prependHTML{Unsafe}, streamAppendHTML{Unsafe}
  and streamPrependHTML{Unsafe} throw a "HierarchyRequestError"
  DOMException when the target is an html element.
- beforeHTML{Unsafe}, afterHTML{Unsafe}, replaceWithHTML{Unsafe}
  and their stream* counterparts throw the same exception when the
  parent is an html element.

Parsing a fragment with an html context element always produces head and
body elements, which is only suitable when replacing all children, so
setHTML{Unsafe}() and streamHTML{Unsafe}() on the html element remain
allowed.

The check, ContainerNode::CheckValidParentForPartialInsertion(), runs
after the Trusted Types compliance check and before the fragment parser
is created, so that it takes precedence over sanitizer config validation
and over removing the node for (stream)replaceWithHTML().

Adds external/wpt/domparsing/tentative/stream-html-element.html from
web-platform-tests/wpt#61748 (tentative until the streaming spec PR
lands), and html-insertion-methods-html-element.html for the
non-streaming methods.

Bug: 573276742, 491743369
Change-Id: If6caf8060b254f5f1d9ad8c0f716b3a503d3066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8576898
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1721116}

--

wpt-commits: a15a3144858f9e81c11abf28858be4cd2a64e80e
wpt-pr: 63805

UltraBlame original commit: fb9ed559b2ed948685d1f675f6b4cb3437bdd930
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Nov 4, 2026
…t parser is running, a=testonly

Automatic update from web-platform-tests
Defer HTMLStream abort while the fragment parser is running

Align HTMLStream's abort algorithm with "abort a fragment parser" in the
spec (whatwg/html#12758): if the parser is running when the
stream is aborted, the abort is deferred until the current run returns,
so the rest of the current chunk is still parsed and the stack of open
elements is not popped in the middle of inserting a node.

While a write() is in flight, the WritableStream already queues abort()
behind it. But after a parser-blocking external script, the parser
resumes from a task with no write in flight, so abort() called from a
streamed inline script or a custom element reaction reached
HTMLSink::abort synchronously, which called StopParsing() and Detach()
while PumpTokenizer() was on the stack and dropped the rest of the
chunk.

HTMLDocumentParser::AbortFragmentParser() records the request while a
pump session is active and PumpTokenizerIfPossible() performs the abort
once the outermost pump returns. Outside a pump the behavior is
unchanged.

Adds external/wpt/domparsing/stream-html-reentrancy.html (and its
resources/slow.js dependency) from web-platform-tests/wpt#61748 at its
final, non-tentative path.

R=masonfchromium.org

Bug: 573252239, 491743369
Change-Id: I9569555cbae7f5be0ca91b3b8ede5b1198a7ad66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8579128
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Reviewed-by: Mason Freed <masonfchromium.org>
Cr-Commit-Position: refs/heads/main{#1721059}

--

wpt-commits: 286b7995a5a3028cee705b5e5f67b0a960dafd44
wpt-pr: 63795

UltraBlame original commit: 017536f25b6eb1008458f9efd92984d7a12b8824
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Nov 4, 2026
…tial insertion methods on the html element, a=testonly

Automatic update from web-platform-tests
Throw HierarchyRequestError for HTML partial insertion methods on the html element

Align the HTML insertion and streaming methods with the WHATWG HTML spec
("filter and pre-insert HTML", "filter and replace with HTML", and
whatwg/html#12758 for the streaming methods):

- appendHTML{Unsafe}, prependHTML{Unsafe}, streamAppendHTML{Unsafe}
  and streamPrependHTML{Unsafe} throw a "HierarchyRequestError"
  DOMException when the target is an html element.
- beforeHTML{Unsafe}, afterHTML{Unsafe}, replaceWithHTML{Unsafe}
  and their stream* counterparts throw the same exception when the
  parent is an html element.

Parsing a fragment with an html context element always produces head and
body elements, which is only suitable when replacing all children, so
setHTML{Unsafe}() and streamHTML{Unsafe}() on the html element remain
allowed.

The check, ContainerNode::CheckValidParentForPartialInsertion(), runs
after the Trusted Types compliance check and before the fragment parser
is created, so that it takes precedence over sanitizer config validation
and over removing the node for (stream)replaceWithHTML().

Adds external/wpt/domparsing/tentative/stream-html-element.html from
web-platform-tests/wpt#61748 (tentative until the streaming spec PR
lands), and html-insertion-methods-html-element.html for the
non-streaming methods.

Bug: 573276742, 491743369
Change-Id: If6caf8060b254f5f1d9ad8c0f716b3a503d3066b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8576898
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Noam Rosenthal <nrosenthalgoogle.com>
Cr-Commit-Position: refs/heads/main{#1721116}

--

wpt-commits: a15a3144858f9e81c11abf28858be4cd2a64e80e
wpt-pr: 63805

UltraBlame original commit: fb9ed559b2ed948685d1f675f6b4cb3437bdd930
zcorpan pushed a commit to whatwg/html that referenced this pull request Nov 5, 2026
Introduce safe and unsafe streaming HTML parsing and insertion methods returning a `WritableStream`:
* `Element` & `ShadowRoot`: `streamHTML()`, `streamHTMLUnsafe()`, `streamAppendHTML()`, `streamAppendHTMLUnsafe()`, `streamPrependHTML()`, and `streamPrependHTMLUnsafe()`
* `NonDocumentTypeChildNode`: `streamBeforeHTML()`, `streamBeforeHTMLUnsafe()`, `streamAfterHTML()`, `streamAfterHTMLUnsafe()`, `streamReplaceWithHTML()`, and `streamReplaceWithHTMLUnsafe()`

Key behaviors and parser updates:
* Stream operations: `writeAlgorithm` and `closeAlgorithm` convert chunks to `DOMString`, append chunks (or an explicit `"EOF"` character on close) to the parser's input stream, and run the fragment parser. `closeAlgorithm` waits for any pending parser-blocking scripts via `fragment parser close promise`. `abortAlgorithm` aborts the fragment parser (deferring via `fragment parser abort requested` if currently running), marks open `script` elements on the stack as already started, and unblocks rendering on pending scripts.
* Displaced reference child: If `referenceChild` is no longer a child of `target` when a node would be inserted before it or when another chunk is written, `invalid reference child steps` error the stream (and reject `fragment parser close promise` if closing) with a `"HierarchyRequestError"` `DOMException` and abort the fragment parser. Elements that would be inserted before a displaced `referenceChild` are created in the `appropriate template contents owner document` with a null custom element registry and dropped, and the adoption agency algorithm skips removing `lastNode`.
* Validation, Trusted Types & DOM mutations: Target validation (throwing `"NotSupportedError"` for HTML/SVG `script` context elements, or `"HierarchyRequestError"` for `html` targets or invalid `parent for HTML streaming`), `HTMLTemplateElement` redirection to `template contents`, and Trusted Types / `SanitizerConfig` validation occur synchronously before returning the stream or mutating the DOM.
* Scripts, custom elements & fragment parsing:
  - Extracts `initialize an HTML fragment parser`. When `runScripts` is true, `script target document` is `context`'s node document; otherwise it is the temporary inert document.
  - Parser-blocking, `defer`, `async`, and module scripts follow normal HTML parser pausing and execution order.
  - Custom element upgrades/callbacks when inserting into a connected target run before any subsequent `script` via a dedicated element queue; other reactions when streaming HTML use the backup element queue.
  - The speculative HTML parser is not started in the fragment case. Speculative fetches from the fragment parser are still allowed, except when sanitizing or for elements that will be dropped. The end (`stops parsing`) returns early for fragment parsers.
  - Elements whose intended parent is the fragment root `html` element are created directly in the target's (or fragment's) node document.
  - SVG `script` elements are only processed when the parser's `script target document` is not the parser's `Document` and the `script` element is connected (which also applies to document parsing when an ancestor of an SVG `script` was disconnected before `</script>`).
  - Elements removed or replaced with their children by the sanitizer are created in the `appropriate template contents owner document` with a null custom element registry and not inserted into the DOM. Their descendants look up a null registry from them too. This also applies to the non-streaming methods that use the HTML fragment parsing algorithm with a sanitizer (`setHTML()`, `setHTMLUnsafe()`, etc.), where previously the whole fragment was parsed (and custom elements upgraded) before sanitization.

Note: Pre-existing adoption agency algorithm edge cases (#13093) are out of scope for this change.

Tests: web-platform-tests/wpt#61748.

Closes #2142.
@zcorpan
zcorpan merged commit 3280b7a into master Nov 5, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants