-
Notifications
You must be signed in to change notification settings - Fork 373
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
A way to detect if a custom element was constructed during customElements.define call? #790
Comments
I made a module to detect it: export var isCustomElementsDefineCall = false
const oldDefine = customElements.define
customElements.define = function(tagName, Constructor) {
isCustomElementsDefineCall = true
oldDefine.call(this, tagName, Constructor)
isCustomElementsDefineCall = false
} So then, import { isCustomElementsDefineCall } from './util/isCustomElementsDefineCall'
class MyEl extends HTMLElement {
constructor() {
if (isCustomElementsDefineCall) {
console.log('created during customElements.define call')
}
}
} now when I detect this case, I can schedule an observation of children. |
An upgrade can happen with children in other scenarios, too. Why not just check to see if the element already has children in the constructor? class MyEl extends HTMLElement {
constructor() {
super();
if (this.children.length) {
console.log('has children when upgraded');
}
}
} These kinds of questions are probably better suited to somewhere like Stack Overflow rather than this issue tracker. You'll probably get answers quicker there anyway. |
About that, that isn't enough. At that point if a child isn't upgraded yet, we can not see upgraded props/methods on the children. That's why I opened #789. So in that case, I create a So as a result of previous discussion in #789 and #787, the last implementation that I had before opening this one was the one in #787 (comment). But now that I've come across the case of defining elements after parsing (all of them at once, because doing them individually in different turns of the JS event loop will be another case), I've discovered that I need to handle this too, but because Here's the order I see in the console when I define elements before parsing:
and if I defer
I may have an error in some code that consumes the At least now the callbacks are firing in all the cases in a way that is almost on par with how/when If the engine was had this implemented, it'd be easy: fire the So, I've gotta see if I can trigger the I bet I can achieve this with another |
Oh, plus, SO is not conducive to discussion: cross-linking issues is not a prime feature, there's no markdown, pasting URL-shortened links in comments fails, etc. It's just not a good discussion medium. I think the questions are better here because they help standards implementers have better visibility into what users of the API are doing or want to do, and how. Do you think this is the case? Or do the implementers view the questions on SO? It doesn't seem like it'd be easy to track anything on SO based on the points of the previous paragraph. |
These kinds of questions are not bugs with the standard and indeed belong on StackOverflow or other forums. Additionally, please realize that for every comment and issue you make you send 295 people an email. So far you have made not one, but five, comments on this thread, some of which are rather repetitive and off-topic. Please be more conservative with how you use other peoples' time and attention, for example by editing your posts instead of re-posting them with slight modifications or follow-up points. |
I just noticed my comment was posted twice due to network disconnection. Nothing I tried to post here was repetitive from my perspective, but fault of GitHub's erroneous way of handling internet connectivity. Sorry if you thought I posted anything twice. My point stands: posting to SO will make any sort of discussion on the topic difficult, and will not help the standards process. The standards process should involve user-centric analysis of what users can/want to do, and SO is obviously not the best place for that. The things I'm trying to discuss are about wants/desires that are otherwise difficult, unintuitive, and error-prone to achieve, and telling people to go to Stack Overflow is similar to saying "shoo fly" without caring about the end user as much as they can be cared for. This is same reason, IMO, why the private fields proposal has such an incredibly high ratio of dislike to like yet "open standards implementers" ignore it. That's how I see it when I'm told to move along to Stack Overflow. Maybe it's something you could consider. |
It's definitely helpful to see what authors want & can do. What we can't really do is to answer any question you may have to do X, Y, or Z. Those things need to be discussed in some other forum, and only when all the options are exhausted, should you post a proposal or file an issue on this issue tracker in the form of what you need it and why you need it with detailed explanation as to why that's impossible, or really hard to do. Just to echo what @domenic said, I can only work 10-12 hours a day to fix bugs & implement new features in WebKit. Every minute I spend reading & responding any comments on this issue tracker is the time I didn't spend fixing bugs. In that sense, any new issue filed on this issue tracker is basically resulting in multiple WebKit bugs not getting fixed or a new feature not getting implemented or implemented later over years. That's a pretty steep price we, as the humanity, are paying if you ask me. Now, many of the issues you filed in the past and present are very insightful, and we've learned quite a few things, and it's totally worth whatever collective time we've spent discussing. However, at times, some of your posts can be repetitive & hard to follow because your understanding of the problem is rapidly evolving throughout the issue over a span of days. So as much as I really appreciate all your enthusiasm, and I really enjoy working with you, I respectfully ask you to study & research the problem space fully before filing a new issue, and try to make your description more concise in the future. |
Thanks for explaining your perspective @rniwa, I appreciate that.
👍 Will do. |
F.e.,
I think one way I can do this is to monkey patch
customElements.define
and set a var.The reason is, because I'm finding that if I define elements after they have already been parsed, then creating a
MutationObserver
in the constructor does not observechildList
because the nodes that are being upgraded already have the children (no DOM mutation happened).I'd like to fire
childConnectedCallback
in this case, but the idea from #789 only works during parsing.The text was updated successfully, but these errors were encountered: