Repository navigation
Cover a few fragment parsing edge cases - #61042
Merged
Merged
Conversation
See whatwg/html#12624 This clarifies a scenario where the allow-DSD flag has to be sticky on the document rather than just a parser flag.
6 tasks done
- Check insertion logic "after body" for template.innerHTML - Check that template.innerHTML takes the custom element registry from the template
annevk
added a commit
to whatwg/html
that referenced
this pull request
Jul 9, 2026
This makes a few key changes to the fragment parsing workflow, to better match existing implementations and tests. - 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 introduces an "root insertion target", which is a `DocumentFragment` to insert into if the parser wants to insert nodes into the root. - In addition to keeping "allow declarative shadow roots" directly on the document, it becomes a parser flag. This removes some confusion that makes some subtle cases use the wrong setting. It is still kept on the document so that it sticks for the "document opening steps" (`document.open()` of a document created elsewhere). - The custom element registry is taken from the target of the fragment parse rather than from the context document. Together with the other changes, this essential for picking the correct registry, e.g., when calling `shadowRoot.innerHTML`. Note that this changes the specified behavior of `template.innerHTML` to have a null registry - this aligns with current implementations and can be changed in a follow-up together with implementation/test changes. - The fragment parsing algorithms take in the target of the parse and infer the context element from that (i.e., it's either the target itself, or its fragment host if it's a `DocumentFragment`). - The "adjusted insertion location" algorithm is separate from the "appropriate place from inserting a node", as the parser internals make some decisions based on the "intended parent" which should remain unchanged by this PR. - The adjusted insertion location" is also an enabler that can be used later on for HTML streaming and sanitize-while-parsing, as it can be the context element instead of the intermediate fragment. - The intermediate inert document is still around. It is needed to avoid creation-time side effects like image loading and custom element constructors from occurring before sanitization. The above changes are a lot closer to how Chromium implements fragment parsing (and given the passing tests, likely WebKit and Gecko as well). Existing tests are aligned with implementations already. Additional tests: web-platform-tests/wpt#61042. Closes #11023 and closes #12661. Co-authored-by: Anne van Kesteren <[email protected]>
rniwa
approved these changes
Jul 13, 2026
nt1m
approved these changes
Jul 13, 2026
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.
See whatwg/html#12624
template.innerHTML