Refactor fragment parsing algorithm to match implementations#12624
Open
noamr wants to merge 32 commits into
Open
Refactor fragment parsing algorithm to match implementations#12624noamr wants to merge 32 commits into
noamr wants to merge 32 commits into
Conversation
annevk
reviewed
Jun 29, 2026
Contributor
Author
|
@shannonbooth do you have a list of WPTs that this fixes? I want to add them to the OP. |
Member
annevk
reviewed
Jul 1, 2026
Contributor
Author
|
Fixed editorial changes, also made the root adjustment for text/comment/PI |
6 tasks
Instead of inserting elements to a fake root element of a connected inert document and then appending them to a `DocumentFragment`, we let the parser insert the root's children straight into that `DocumentFragment`. This is done by having an "adjusted insertion target" that the parser uses to route insertions desined to the root of the stack directly into the fragment. The observable behavior change is in subtle places that check for connectedness when insertion, like radio buttons. This is also creates an enabler that can be used later on for HTML streaming, as the "adjusted insertion target" can be the context element instead of the intermediate fragment. Note that we still need some notion of the intermediate inert document, to avoid creation time side effects like image loading and custom element constructors to occur before sanitization. (This resembles blink implementation, more than the current wording) Closes #11023
455575a to
032ab92
Compare
This reverts commit 3b8d929.
That needs to stay on document as otherwise we change what open() does.
Member
|
@noamr AI identified to more potential subtle issues here (bit wordy unfortunately):
|
- Explicitly use template's custom registry - Adjusted insertion location should adjust overrideTarget
Contributor
Author
Fixed. Special-casing the template contents case to take the CER from the template element.
Fixed. "adjusted insertion location" now takes in the override target. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes a few key changes to the fragment parsing workflow, to better match existing implementations and tests.
DocumentFragment, we let the parser insert the root's children straight into thatDocumentFragment. This introduces an "adjusted root insertion target", which is aDocumentFragmentto insert to if the parser wants to insert nodes to the root.allow declarative shadow rootsdirectly from the document, it becomes a parser flag. This removes some confusion that makes some subtle cases use the wrong setting. It is taken from the document only in the "document opening steps" (document.open()of a document created elsewhere), as it's the only place where this setting is sticky.shadowRoot.innerHTMLDocumentFragment).The above changes are a lot closer to how blink implements fragment parsing (and given the passing tests, likely WebKit and Gecko as well).
Closes #11023
document.open()on an XHR response(See WHATWG Working Mode: Changes for more details.)
/document-lifecycle.html ( diff )
/dynamic-markup-insertion.html ( diff )
/parsing.html ( diff )
/xhtml.html ( diff )