-
Notifications
You must be signed in to change notification settings - Fork 382
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
Consider adding a childrenChangedCallback or something #619
Comments
Now in almost all implementations connectedCallback behave as connectedAndParsedChildrensCallback and child nodes are fully accessible. I think need left as is. For example if need header/footer can write this.innerHTML="Header ..."+this.innerHTML+"Footer..."; If custom component has nested element, and connectedCallback has empty child list - this event absolutelly useless for web developers. Custom elemets are very simple, but if read specification - very very complicated. Must be so: |
Whether that's true or not, I think a |
Let's assume that's true. As far as I know there's only two mostly complete implementations of this. Something happening in "almost all" of two isn't that persuasive to me.
Is there a specific proposal you're referring to? I don't think anyone is proposing the behavior of innerHTML will change. That uses fragment parsing. Custom elements get upgraded and see populated child nodes (unless another custom element modifies them.) I think there's a slightly bigger point here, and that's what an element should do. The built-in elements can all be created by document parsing, fragment parsing (such as innerHTML), createElement, etc. and you can modify their children and they respond to those modifications. Jan is codifying some of these patterns in this checklist; "detached instantiation" and "content changes" are relevant to this discussion. One side effect of having main document and innerHTML parsing be so different means you pretty much have to respond to content changes, although it's more work. Another argument I have heard against responding to content changes is performance. Some authors want to process custom elements like macros and it's inefficient for them to continue to get connectedCallbacks. HTML has a legacy wart like that—isindex. Ideally we want something where it's possible, even easy, to do the right thing (which probably means responding to content changes.) |
If there is such an implementation, I think it should be called both on when the children are first added as well as when children change. There's a similar proposal in SkateJS and I've been playing around with implementations in the corresponding PR. The problem arose from needing to get nodes for a certain slot so that we could It seems that if a |
Just sketching out how a polyfill (used as a mixin) for this might look: http://www.webpackbin.com/EJ66Qma4G. |
i'm hugely in favor of not leaving MutationObserver partially re-implemented in Web Components (only having a I don't care about characterData, but it seems odd to fix the |
@rektide to add to that, the |
parsedCallback |
@treshugart rather than introduce a new kind of eventing- I'm simply not familiar with what a slot is, so trying to interpret the language in skatejs/skatejs#863 is rather hard. If it has a pertinent impact on Custom Elements, I'd like to see it clearly defined in it's own area, rather than jumbled into this current discussion, although I'm fine with this issue referencing that specific topic & vice verse. |
@rektide That issue in Skate was just a reference for a more specific implementation we were spiking that is related to the same use-cases that a |
I've implemented this myself, and basically #668 makes it very difficult to get it just right. For instance, during parsing, the order of These sort of inconsistencies make it difficult to write clean programs. In React, Vue, Angular, etc, the order of callbacks are guaranteed. People coming from those libraries will stumble on this. |
For reference, here's my implementation: Mine is Using |
This isn't true, as I've found out in #668 (see my above comment). @treshugart Have you encountered any issues as I described in #668? The ordering of connectedCallbacks for children of an element is up-the-tree or down-the-tree depending on situations. Also, when the direction is down-the-tree, I'm not certain that detected elements will be upgraded when I observe them. |
@treshugart I think I've sent this your way before, but for the benefit of others on the thread, the above mentioned behavior is changing so If |
Is this different from #550? |
I think this a duplicate of the issue #550. |
This issue might be slightly different, in that #550 talks about just when children are added/removed, but this issue talks about other types of mutations as well (like character data change, and changes on child elements besides adding/removing). Maybe both issues can converge somehow. |
For anyone stumbling across this, help is on the way: https://github.com/WebReflection/html-parsed-element |
Chromium has got feedback from developers (for example Issues 676365, 672732, 658119, 639847, etc.) which indicates some confusion about when child nodes are accessible in a custom element's connectedCallback around construction time. Some confusion is probably because Blink had bugs, but this is inherently a bit confusing—sometimes the connectedCallback after upgrade has the child nodes (fragment parsing, upgrade on insertion) and sometimes it doesn't (parsing.)
There's some relevant discussion on Issue 551, which includes the suggestion to add a "children changed" callback.
I suspect some use case elicitation is in order here, for example, I've also heard people discuss a "parser done adding children" callback which is semantically very different to "children changed", and I note mutation observers can observe not just children but also subtrees.
Another idea could be to let MutationObservers have an option to deliver changes at CEReactions time. I haven't really thought hard about the implementation feasibility of this, but it might be worth considering as an alternative to developing callbacks piecemeal, and the dynamism of disconnect may be useful.
The text was updated successfully, but these errors were encountered: