-
Notifications
You must be signed in to change notification settings - Fork 376
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
[IDEA] deferred upgrade for Custom Elements. #559
Comments
Does the issue make sense? Let me know if I need to explain it differently. Essentially, _I never have any problem if my elements don't have to be upgraded_ (i.e. the classes are registered before the elements are ever created). The problems arise when the elements are created before the classes are registered, in which case they need to be upgraded and that means _causes some of my library code to execute before all the classes have been registered and therefore the code can fail because the custom element classes are minimally coupled and depend on things existing on all the elements, where those things are defined in multiple custom element classes_. |
Here's the problem explained as simply as I can, and with possibly incorrect assumptions as I'm not completely familiar with Chrome's v0 implementation: Suppose I wish to register two element classes, <some-el>
<other-el>
</other-el>
</some-el> Then, the following JS is executed: document.registerElement('some-el', SomeElement)
document.registerElement('other-el', OtherElement) In an attempt to describe the problem I see from observing Chrome's v0 behavior, it seems that the first call to I don't have a simple reproduction, but will post back if I do. |
We've visited this idea before and the problem is that we'll delay the painting of a custom element during parsing until all of its children are parsed, which is not acceptable. |
@rniwa Although I run <some-el>
<other-el>
</other-el>
</some-el> then when the However, if the elements are attached into DOM after the class registrations, then the So, it seems there just needs to be some type of mechanism that can guarantee that But, I'm not even sure why if I run my
|
I would really urge you to stop making assumptions based on old implementations, and actually read the spec. There are so many unfounded assumptions here in these (very long) posts, that I don't have time to walk you through where they are wrong. |
@domenic I will strive to do that. Here is simple reproduction of the problem on jsfiddle (tested in Chrome): https://jsfiddle.net/dgbqdL33 (look at console output). In Is this fixed in v1? |
I'd suggest you trying it in Chrome Canary with v1 syntax and so on. Or read the spec. |
@domenic The same problem persists using v1 API in Chrome Canary (see console output): https://jsfiddle.net/wkwmzLwL. This is problematic because a parent element may need to have branching logic depending on which type of custom-element children are detected. f.e. class SomeElement extends HTMLElement {
connectedCallback() {
for (let child of this.children)
if (child instanceof SomeElement)
// ...
else if (child instanceof OtherElement)
// ...
else if (child instanceof AnotherElement)
// ...
}
} This can be solved using a timeout hack, so the code would become class SomeElement extends HTMLElement {
connectedCallback() {
setTimeout(() => {
for (let child of this.children)
if (child instanceof SomeElement)
// ...
else if (child instanceof OtherElement)
// ...
else if (child instanceof AnotherElement)
// ...
}, 0)
}
} Here's a fiddle that shows that the hack works (see output): https://jsfiddle.net/aqp4uaja |
I think this problem also goes away if we add back |
For now, you can work around it by notifying parent element from a child element's |
True, if that callback would be fired when an element is upgraded, at which point we can run an
But as I mentioned earlier, that (child-to-parent notification/observation) doesn't work with distribution into closed shadow trees, which is why I've changed my API to be parent-to-child which should always work, just that I've had to do some hacks like with |
Perhaps what we need is an event that fires when a node gets assigned to some slot? Sort of the counterpart of |
@rniwa I think that would be handy! That is similar to the idea I had with |
Which criteria would cause a |
@trusktr if you still think you need such events, could you explain them clearly in a new issue? This one is rather convoluted and hard to digest. Thanks. |
I'm not sure if upgrade is async in the new spec, but in v0 in Chrome it appears not to be (at least that is my guess based on the hacks I've described in #558.
Here I propose that Custom Element class registration should not cause immediate upgrade, and should wait for the next turn, at which point the engine can upgrade elements in depth-first order with some guarantee that all the necessary classes have already been registered.
I believe that this would prevent me from requiring the hacks described in #558.
The text was updated successfully, but these errors were encountered: