Repository navigation
Description
While reviewing #12758 (stream*HTML*), we identified several pre-existing issues in the HTML parser's adoption agency algorithm (particularly its interaction with parser-level sanitization and custom element registries, as well as intendedParent resolution).
Filing these separately so they can be addressed independently of #12758:
-
furthestBlockretains a null custom element registry when reparented out of a removedformattingElement:
When an element is created inside an ancestor whose sanitizer action is"Remove", create an element for a token sets itscustom element registryto null. If the adoption agency algorithm later reparentsfurthestBlock(vialastNode) intocommonAncestorbecauseformattingElementwas removed,furthestBlock'scustom element registryremains null even though it is now in the kept subtree, preventing subsequent descendant elements from looking up a registry via their intended parent. -
furthestBlock's children briefly enter the target tree whenformattingElementis"Remove":
Step 4.14 insertslastNode(furthestBlock, along with its existing children) at the appropriate place for inserting a node givencommonAncestorbefore steps 4.15–4.16 createnewElement(which is not inserted whenformattingElement's sanitizer action is"Remove") and movefurthestBlock's children intonewElement. As a result, whencommonAncestoris in the live tree,furthestBlock's children are momentarily inserted into the target tree (triggering insertion steps,connectedCallback,iframeloading, orscriptpreparation) even though they end up inside the removednewElement. -
Clones created in the inner loop below a removed ancestor get the live document and custom element registry:
In the inner loop (step 4.13.6), create an element for a token is always called withcommonAncestorasintendedParent. If an outer cloned formatting element in the inner loop (orformattingElementitself) has a sanitizer action of"Remove", inner clones whose own sanitizer action is"Keep"still receivecommonAncestor's document and custom element registry (allowing synchronous custom element constructors to run in the live document), even though they end up appended to a removed ancestor subtree. -
Inner loop passes
commonAncestordirectly asintendedParent:
Step 4.13.6 passescommonAncestordirectly asintendedParentto create an element for a token, rather than thetarget parentof the appropriate place for inserting a node givencommonAncestor. WhencommonAncestoris a<template>element or triggers foster parenting, the intended parent used during cloning diverges from normal parser insertion (insert a foreign element), affectingnodeDocumentandcustom element registrylookup.
Activity
[-]Parser: pre-existing issues in adoption agency algorithm (sanitizer/intended parent) and SVG script end-tag processing[/-][+]Parser: pre-existing issues in adoption agency algorithm (sanitizer and intended parent)[/+]Add streaming HTML insertion methods
Add streaming HTML insertion methods
[-]Parser: pre-existing issues in adoption agency algorithm (sanitizer and intended parent)[/-][+]Adoption agency algorithm issues (sanitizer and intended parent)[/+]