Repository navigation
Un-tentative streamHTML tests - #61748
Conversation
|
Should this be |
7997f11 to
608fd49
Compare
Fixed |
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}
… 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).
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.
00abb31 to
e6e8fd7
Compare
…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.
AI feedbackReviewed at 237a8db, alongside my comment on whatwg/html#12758. Blockers
|
… the end and the adoption agency
Thanks, fixed in b414768 (spec side in whatwg/html@a62174f9b):
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 |
AI feedbackRe-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 Blockers
Suggestions
Nits
|
… start-tag abort check
…laces referenceChild
|
Addressed:
|
…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
…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
…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
…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
…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
…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
…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
…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
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.
Un-tentative the
streamHTML()family of tests, now that whatwg/html#12758 is landing:domparsing/tentative/intodomparsing/, and thestreamAppendHTMLUnsafe()+<template for>tests out ofhtml/dom/partial-updates/tentative/intohtml/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 parentWEB_FEATURES.ymlfiles.ownerDocumentand stream realm,<noscript>inside template contents, removed<img>resource fetches, positional methods on nodes without a parent).streamReplaceWithHTML(Unsafe)in the Trusted Types streaming tests that were missing it.<html>element handling (streamAppend/PrependHTML(Unsafe)on<html>and positional methods on<head>/<body>throwingHierarchyRequestError;streamHTML(Unsafe)on<html>replacing/implying<head>and<body>).document.write()implyingdocument.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).close()waiting for pending parser-blocking scripts while not waiting for externaldeferor non-asyncmodule scripts,abort()unblockingblocking="render"defer scripts, stylesheets not blocking streamed scripts, re-entrantabort()/write()/close(), and SVG<script>withrunScripts).commentsoption (including comments split across chunks) and<form>inreplaceWithChildrenElements/removeElementsnot becoming the form owner.<template shadowrootmode>inserted as a plain<template>, nullreferenceChildcaptured at call time,Uint8Arraychunk stringification, and exception ordering (Trusted TypesTypeErrorvs.NotSupportedErrorvs.HierarchyRequestErrorvs. sanitizer config validation).