-
Notifications
You must be signed in to change notification settings - Fork 299
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
Custom element callback/promise for "connected and parsed" #662
Comments
Previously: WICG/webcomponents#619, WICG/webcomponents#550. Video/source does not appear to work in the way you describe:
There are a couple elements which do work this way. You can find them by searching for things that trigger when the element is popped off the stack of open elements. It appears that list consists of:
I'm not sure it's worth spreading this pattern further, as opposed to just saying it's a legacy pattern. The most compelling examples you might want to emulate are style/script (i.e., don't apply styles/execute script until all of the text content is present). But do we see a lot of people trying to do the style/script case? My impression is it's mostly been people who are unwilling to put in the work of making their element properly reactive to descendant changes, i.e. they want to use children as configuration for initial setup, and not as part of a dynamic tree. |
Yeah, that feels like a bug as it makes the fetching nondeterministic.
I guess you would if your web component was interpreting the input. Eg a babel/jsx component. A responsive image web component would likely want the same pattern, assuming we didn't already have responsive images. I don't feel strongly about this, so I'll leave it for others to add use cases. |
Although, I guess |
I agree with @domenic here. It will open the gates for a lot of wrong-doing. As for browser differences, do we have tickets for safari and firefox to correct that behavior? |
Not yet. Sorry it took me a while to confirm the correct behaviour. I'll
file bugs. It's covered by tests.
…On Fri, 29 Jun 2018, 17:30 Caridy Patiño, ***@***.***> wrote:
I agree with @domenic <https://github.com/domenic> here. It will open the
gates for a lot of wrong-doing. As for browser differences, do we have
tickets for safari and firefox to correct that behavior?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#662 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFtmvUS2cIIafwPnuL76hO00B9sepv9ks5uBlY_gaJpZM4U8yZx>
.
|
I've definitely wanted to have behaviour similar to this issue for simple inline code. e.g. For this sort've use case: <math-plot>
<module-script>
export default function(x) {
return x**2
}
</module-script>
</math-plot> In this case it's the children of the I tried to create a customized builtin
On the other hand this particular problem could be solved by ensuring that the e.g. Just defer the class ScriptLike extends HTMLElement {
// ...
}
if (document.readyState === 'interactive'
|| document.readyState === 'complete') {
customElements.define('script-like', ScriptLike)
} else {
document.addEventListener('DOMContentLoaded', _ => {
customElements.define('script-like', ScriptLike)
})
} |
Help is on the way: https://github.com/WebReflection/html-parsed-element |
Normally developers just add |
Imo that's a bad idea for at least two reasons: a) it won't solve problems related to dynamic creation/updating of elements via e.g. morphdom, That would introduce a mess of |
Filed WICG/webcomponents#809 to track this in web components repository. |
I can help with that. 😄 One good use case might be in my Svelte custom element polyfill, Doing this well is of course a bit tricky if you're balancing performance concerns. Funny enough, my workaround ended up looking a bit like, uh... a light "shadow" DOM of sorts... in order to efficiently get out of the way of the parser to facilitate rendering ASAP (at least on the next |
Developers seem to assume that
connectedCallback
means the element's contents will be present. This isn't helped by browser differences (demo). Safari & Firefox get it wrong and show some element contents inconnectedCallback
depending on loading speed. Chrome appears to get it right.However, consider an element like
<video>
. Because<video>
's contents influence what should be loaded, the content shouldn't be considered until the parser has stopped adding elements into the<video>
, else you can end up with pointless double fetching.Do we need something similar for custom elements? This could be an additional callback, or perhaps even
htmlElement.parsed
, which is a promise that resolves once the element has fully parsed. This would be useful in other situations too, asdocument.documentElement.parsed
would be similar to DOM-ready.The text was updated successfully, but these errors were encountered: