Repository navigation
Implement out-of-order streaming using <template for> - #76083
hjanuschka wants to merge 1 commit into
Conversation
|
EWS run on previous version of this PR (hash 61b0a3d) Details |
61b0a3d to
51c4f27
Compare
|
EWS run on previous version of this PR (hash 51c4f27) Details |
51c4f27 to
4eeb56a
Compare
|
EWS run on previous version of this PR (hash 4eeb56a) Details |
4eeb56a to
4b41b5b
Compare
|
EWS run on previous version of this PR (hash 4b41b5b) Details |
4b41b5b to
058d5dd
Compare
|
EWS run on previous version of this PR (hash 058d5dd) Details |
058d5dd to
e461cf1
Compare
|
EWS run on previous version of this PR (hash e461cf1) Details |
AI-generated review feedback (Claude)This review was generated by Claude, an AI model, at my request. Findings marked reproduced were observed in a local Debug build of e461cf1; the rest come from reading the code and comparing it with the specification and Chromium. Line links point at e461cf1. Re-entrancy (blocking)
Parser integration
Style invalidation
Performance
Code
Tests and expectations
Commit messageThe function list sits under |
|
Given what AI found we need more test coverage here as well. Especially for the more esoteric scenarios. |
e461cf1 to
85088cf
Compare
|
EWS run on previous version of this PR (hash 85088cf) Details |
85088cf to
835f9a3
Compare
|
EWS run on previous version of this PR (hash 835f9a3) Details |
There was a problem hiding this comment.
looking forward, let me know if you want me to address anything further 🎉
highlights:
- nested guard: the counter now goes on scope.document(), so patches nested in patches are guarded too
- marker removal runs inside the same ThrowOnDynamicMarkupInsertionCountIncrementer (mutation-events test is WebKit-only, WPT can't enable those)
- patched nodes follow the insertion target for document/tree scope/registry, so custom elements are parser-constructed; text merges with the node before the insertion point, across write() chunks too
- shadowrootmode wins over for where declarative shadow roots are disallowed, per the "in head" steps
- body->html widening applies after the insertion-target redirect
- style invalidation reworked the way you suggested: ChildChangeInvalidation runs the sibling checks for parser insertions into already-finished parents, and invalidateSiblingAndPositionalStyles() is gone
- perf nits done: PI target checked before parsing its data, unused HTMLParserOptions::templateFor removed, the for branch no longer duplicates the attach path, dead foster-parenting branch gone; preload scanning for patches is a follow-up
each fix has a test that fails without it (7 of the 10 new ones are red on the previous revision). also fixed two upstream test bugs along the way (move-cross-document asserted around its own inserted script, only-html-001 was missing resources/template-for.xhtml). all new and fixed tests are upstream: web-platform-tests/wpt#65568
AI-generated review feedback (Claude), second passThis follow-up was generated by Claude, an AI model, at my request, against 835f9a3. Everything marked reproduced was observed in a local Debug build of that commit. FixedThe test cases from the first pass now behave as the specification says (reproduced):
Still crashing: the guard is on a node's document, not the parser'sBoth guards use a node's document: // A nested patch whose scope moved into the parent document.
const doc = iframe.contentDocument;
doc.open();
doc.write(`<div id="target"><?start name="outer">old<?end></div>`);
doc.write(`<template for="outer"><?start name="inner"><iframe></iframe><?end>`);
document.body.append(doc.getElementById("target"));
document.querySelector("#target iframe").contentWindow.onpagehide = () => doc.write("<p>Hi");
doc.write(`<template for="inner">New</template></template>`);// Marker removal after the target moved, with MutationEventsEnabled=true.
doc.open();
doc.write(`<div id="target"><?start name="p">old<?end></div>`);
doc.write(`<template for="p">A`);
document.body.append(doc.getElementById("target"));
document.addEventListener("DOMNodeRemoved", e => {
if (e.target.nodeType == Node.PROCESSING_INSTRUCTION_NODE)
doc.write("<p>Hi"); // once
});
doc.write(`</template>`);Guarding the document the construction site parses into ( Correction:
|
835f9a3 to
88f99ed
Compare
|
EWS run on previous version of this PR (hash 88f99ed) Details |
|
@annevk thanks, both points from your review fixed! |
88f99ed to
aafcd3c
Compare
|
EWS run on previous version of this PR (hash aafcd3c) Details |
https://bugs.webkit.org/show_bug.cgi?id=324175 Reviewed by NOBODY (OOPS!). whatwg/html#13036 Add HTMLTemplateElement.htmlFor and use the `<?marker>`, `<?start>` and `<?end>` processing instructions from 326324@main as parser insertion points, so that content arriving later in the stream can be placed into a part of the document that has already been parsed. Redirect parser output into the selected insertion point, remove the replaced range and the markers, and keep parser behaviour across fragments, shadow roots, nested patches and scripts. This sits behind the new HTMLTemplateForEnabled setting, which is testable and off, separate from the processing instruction setting so the parser change can be enabled on its own. The patching machinery is careful about the following, each covered by a layout test that fails without the corresponding code: - Preparing a patch and removing the markers can fire pagehide in removed iframes, and mutation events where those are enabled, from inside the tree builder. A handler calling document.write() would re-enter it, so both run inside a ThrowOnDynamicMarkupInsertionCountIncrementer, as the parser already does for custom element constructors. The guard goes on the document the parser writes into and on the scope's document, which differ when the patch is nested inside another <template for>, owned by a template content document, and when script moved the patch target into another document mid-parse. - Removing the markers uses remove() rather than parserRemoveChild(), because removeNodeWithScriptAssertion() disconnects every subframe under the parent rather than under the removed node, which would take out iframes inside and beside the patched content. - Nodes for patched content are created in the patch target's document, tree scope and custom element registry, not in the template content fragment's, so custom elements are constructed by the parser rather than upgraded, and text honours the target's length limits. - Patched text merges with a Text node already before the insertion point, matching how the parser appends elsewhere. - Patch target resolution is indexed. Document keeps a map from marker name to the <?marker> and <?start> processing instructions, registered on insertion and updated on removal, data mutation and document adoption, so preparing a patch costs the number of markers with that name instead of a walk over every descendant of the scope, which made N patches into an N-item document quadratic (2000 patches: ~55ms -> ~3ms). Duplicate names resolve to the first marker in tree order at lookup, and markers in detached subtrees stay indexed because a patch scope can lie inside one. - Per whatwg/html#13075, `for` applies whenever no declarative shadow root was attached: an invalid shadowrootmode, a context that disallows declarative shadow roots such as innerHTML, or a host that cannot have or already has a shadow root all leave `for` in effect. - The scope in which markers are looked up widens from body to html also when the enclosing template is itself patching a body child. - Parser insertions into an element that has already finished parsing run the sibling style checks in ChildChangeInvalidation per insertion, instead of relying on invalidateAfterFinishedParsingChildren, which only runs when the parser finishes an element it opened itself. This keeps `:first-child` and friends correct while a patch streams and after it finishes. The remaining failures in the imported suite are all features WebKit does not implement: the streaming and append APIs, the Sanitizer, and the HTMLUnsafe setters. Two upstream test issues are fixed in place and belong upstream too: template-for-move-cross-document asserted around a <script> it had inserted itself, and template-for-only-html-001 was missing its resources/template-for.xhtml support file, so it failed in every engine. Tests: fast/parser/template-for-mutation-events-cross-document.html fast/parser/template-for-mutation-events.html fast/parser/template-for-shadowrootmode-not-attached.html imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/ * LayoutTests/fast/parser/template-for-mutation-events-cross-document-expected.txt: Added. * LayoutTests/fast/parser/template-for-mutation-events-cross-document.html: Added. * LayoutTests/fast/parser/template-for-mutation-events-expected.txt: * LayoutTests/fast/parser/template-for-mutation-events.html: * LayoutTests/fast/parser/template-for-shadowrootmode-not-attached-expected.txt: Added. * LayoutTests/fast/parser/template-for-shadowrootmode-not-attached.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/dom/idlharness.https_include=HTML.+-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/reflect-html-for-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-abort-during-patch-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-abort-during-patch.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-append-element-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-append-text-and-element-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-append-to-head-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-case-sensitive-dom-inserted-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-case-sensitive-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-cross-document-pagehide-dynamic-markup-insertion-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-cross-document-pagehide-dynamic-markup-insertion.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-custom-element-timing-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-custom-element-timing.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-empty-hash-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-foster-parenting-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-gradual-append-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-html-setters-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-iframe-in-patch-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-iframe-in-patch.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-innerHTML-ambiguous-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-innerHTML-within-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-invokes-pagehide-with-end-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-invokes-pagehide-without-end-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-cross-document-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-cross-document.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-only-html-001-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/resources/template-for.xhtml: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-end-while-appending-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-marker-while-appending-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-start-while-appending-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-move-while-appending-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-multiple-cases-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-multiple-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-mutation-records-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-nested-body-scope-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-nested-body-scope.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-nested-pagehide-dynamic-markup-insertion-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-nested-pagehide-dynamic-markup-insertion.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-nested-patch-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-null-in-pi-data-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-null-in-pi-data.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-pagehide-dynamic-markup-insertion-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-prepend-element-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-prepend-text-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-replace-children-with-element-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-replace-children-with-text-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-replace-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-sanitization-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-script-children-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-script-eval-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-script-replace-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-shadow-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-shadow-nested-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-shadow-root-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-streaming-positional-styles-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-streaming-positional-styles.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-style-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-style-in-head-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-supersedes-invalid-shadowrootmode-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-text-node-merging-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-text-node-merging.html: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-title-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-unclosed-content-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/w3c-import.log: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-duplicate-markers-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-duplicate-markers.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-marker-name-mutation-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-template-element/template-for/template-for-marker-name-mutation.html: Added. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/dom/Document.cpp: * Source/WebCore/dom/Document.h: * Source/WebCore/dom/Node.cpp: * Source/WebCore/dom/ProcessingInstruction.cpp: * Source/WebCore/dom/ProcessingInstruction.h: * Source/WebCore/html/HTMLTemplateElement.cpp: * Source/WebCore/html/HTMLTemplateElement.h: * Source/WebCore/html/HTMLTemplateElement.idl: * Source/WebCore/html/parser/HTMLConstructionSite.cpp: * Source/WebCore/style/ChildChangeInvalidation.cpp: (WebCore::HTMLTemplateElement::htmlFor const): (WebCore::HTMLTemplateElement::setHTMLFor): (WebCore::HTMLTemplateElement::insertionTarget): (WebCore::HTMLTemplateElement::insertionNextChild): (WebCore::HTMLTemplateElement::prepareContentPatching): (WebCore::HTMLTemplateElement::finishParsingChildren): (WebCore::insert): (WebCore::HTMLConstructionSite::insertHTMLTemplateElement): (WebCore::HTMLConstructionSite::insertTextNode): (WebCore::HTMLConstructionSite::treeScopeForCurrentNode): (WebCore::HTMLConstructionSite::containerForCurrentNode): (WebCore::HTMLConstructionSite::ownerDocumentForCurrentNode): (WebCore::registryForCurrentNode): (WebCore::Style::ChildChangeInvalidation::invalidateAfterChange): Co-authored-by: Noam Rosenthal <nrosenthal@chromium.org>
aafcd3c to
9e2b7df
Compare
|
EWS run on current version of this PR (hash 9e2b7df) Details |
🧪 webkitpy
🧪 api-mac
9e2b7df
9e2b7df
🛠 playstation