Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fragment parsing algorithm appears to be wrong when invoked from innerHTML setter of template element #61

Open
pshaughn opened this issue Feb 11, 2020 · 2 comments

Comments

@pshaughn
Copy link

It's possible there's some other piece here that I'm missing, but it looks like https://w3c.github.io/DOM-Parsing/#dfn-fragment-parsing-algorithm tells us to make a document fragment on the node document of the context element, and then append nodes to it. This has the potential to enqueue upgrade reactions on those nodes if they match custom element definitions.

However, if we're setting the innerHTML of a template, we want to stay away from the node document of that template element, using the associated inert template document instead and not enqueuing upgrade reactions.

https://w3c.github.io/DOM-Parsing/#dom-innerhtml distinguishes the template as a special case, but only after it's already done calling the fragment parsing algorithm; the upgrade reactions have already been queued before we check if the context object is a template.

The second case of this WPT test checks when upgrades happen in this situation, and browsers are passing it, which implies the specification isn't matching browser behavior: https://github.com/web-platform-tests/wpt/blob/master/custom-elements/reactions/Document.html

bors-servo pushed a commit to servo/servo that referenced this issue Feb 13, 2020
Upgrade nodes to custom elements on insertion, even if they're not connected to a Document

<!-- Please describe your changes on the following line: -->
After comparing tests to specs, I filed whatwg/dom#833 and made this change to match what I believe the spec should be saying to reflect Firefox/Chrome/Safari shared behavior.

I also filed w3c/DOM-Parsing#61 because this change revealed that custom elements created in a template's innerHTML setter weren't behaving themselves and the spec seemed not to reflect reality about them.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #24992 and fix #25004; they are relevant to #25007 but don't fix all the subcases thereof.

<!-- Either: -->
- [X] There are tests for these changes

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bathos
Copy link
Contributor

bathos commented May 7, 2022

It looks like there are two points where the spec is saying to upgrade in the innerHTML setter with a template element: even if the parsing case you desribed here were fixed, I think “try to upgrade” for any given CE produced during parsing would still get hit at step 7.2.2 of insert a node. Is that accurate?

Browsers appear to do what I’d have figured is the correct behavior in terms of intent (i.e., they do not upgrade during parse or during insertion) but it seems like the innerHTML setter steps are pretty far removed from this. There also may be a mistake at step 3 because it assigns a new value to context object, but that seems to be a defined term, not a regular local variable. I’d have guessed an algorithm can’t assign to such things but am not certain.

(Seems like this would be a bit safer & easier to reason about if the definition in DOMParsing had remained generic but the HTMLTemplateElement interface had defined its own innerHTML attribute with its own steps, but I’m guessing it’s too late for that now.)

@pshaughn
Copy link
Author

pshaughn commented May 8, 2022

I haven't looked back at the relevant specs more recently to see what they say now, but whatwg/dom#833 had to do with the question you're asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants