- Notifications You must be signed in to change notification settings
- Fork 3.2k
Commit 4c4c813
and
authored
Refactor fragment parsing algorithm to match implementations
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 <annevk@annevk.nl>1 file changed
Lines changed: 164 additions & 135 deletions

























