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

Make custom element definition trigger in-document upgrades #1204

Merged
merged 1 commit into from
May 10, 2016

Conversation

domenic
Copy link
Member

@domenic domenic commented May 5, 2016

This was part of the previous conclusion in
WICG/webcomponents#419, but never got added
back to the spec:

@dominiccooney, thanks for finding. Not sure if this is the best way to spec it; advice appreciated. As noted in the new HTML comment in the source, it would be equivalent in spec language to just "try to upgrade" all elements in the document.

BTW the reason for "this CustomElementRegistry's relevant global object's Document object" instead of "the current global object's Document object" is because in cases like otherWindow.customElements.define.call(window.customElements, "x-foo", XFoo) the actual element definition will be added to window.customElements ("this CustomElementRegistry"), so it should be window.document that gets crawled for upgrade candidates, not otherWindow (= "the current global object").

@dominiccooney
Copy link

LGTM.

@domenic domenic added the addition/proposal New features or enhancements label May 6, 2016
@annevk annevk assigned domenic and unassigned annevk May 9, 2016
@annevk
Copy link
Member

annevk commented May 9, 2016

This needs rebasing, most likely due to #1209.

<li><p>Let <var>upgrade candidates</var> be all elements in <var>document</var> whose namespace
is the <span>HTML namespace</span> and whose local name is <var>localName</var>, in tree
order. Additionally, if <var>extends</var> is non-null, only include elements that have an
attribute named <code data-x="attr-is">is</code> whose value is <var>name</var>.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surprised me a little bit since it means that a script that runs during parsing can remove the is="" attribute and it'll have an effect. Should we not store it on an internal slot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what scenario are you specifically concerned about? Here is my guess:

<!DOCTYPE html>
<script>
customElements.define("x-a", class extends HTMLElement {
    constructor() {
        super();
        document.querySelector("p").removeAttribute("is");
    }
});
</script>

<p is="x-b"></p>
<x-a></x-a>

<script>
customElements.define("x-b", class extends HTMLParagraphElement {}, { extends: "p" })''
</script>

In this scenario, as you say, the x-a constructor runs and removes the is="x-b" attribute from the <p>. Then, when we later run customElements.define("x-b", ...), the <p> is not upgraded.

That seems totally expected to me. I guess it is a little contradictory with the idea behind the current sentence:

After a custom element is created, changing the value of the is attribute does not change the element's behaviour.

But I don't think it's surprising, and it doesn't even contradict a strict reading of that sentence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That or simply <p is="x-b"></p><script>document.querySelector("p").removeAttribute("is")</script>. I think I misremembered that we planned on guarding against that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, that's of course a simpler repro.

I think there was a general sentiment that "is only gets read once" and that changing it doesn't impact things. But I don't think it was ever formalized, and for edge cases like this I don't think we specifically wanted to preserve the originally-parsed is value.

I'll rebase.

This was part of the previous conclusion in
WICG/webcomponents#419, but never got added
back to the spec:

- WICG/webcomponents@c4a829a
  removed all auto-upgrading
- WICG/webcomponents@70b9d8d
  only added it back for when you insert an element into a document, not
  for when you define an element.
@domenic
Copy link
Member Author

domenic commented May 9, 2016

Rebased.

@domenic domenic assigned annevk and unassigned domenic May 9, 2016
@annevk annevk merged commit 11bdd70 into master May 10, 2016
@zcorpan zcorpan deleted the fix-upgrades-on-define branch May 16, 2016 12:11
@domenic domenic added the topic: custom elements Relates to custom elements (as defined in DOM and HTML) label May 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: custom elements Relates to custom elements (as defined in DOM and HTML)
Development

Successfully merging this pull request may close these issues.

3 participants