Using with shadow-dom doesn't trigger onload function
See original GitHub issueimport bel from 'bel';
export default class MyApp extends HTMLElement {
createdCallback() {
let greeting = this.getAttribute('greeting');
let html = bel`
<div>
<div id="quotes">
<div class="header" onload=${() => console.log('test')}>
${greeting ? greeting : 'Hello!'}
<content select="my-name"></content>
</div>
<div class="body">
<content select="my-profile"></content>
</div>
</div>
</div>
`;
this.createShadowRoot().appendChild(html);
}
}
Which I use:
<my-app greeting='Hi'>
<my-name>Hello</my-name>
<my-profile>
This is my profile
</my-profile>
</my-app>
The DOM renders fine, but on load there is nothing in the console.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
I want to wait until the Shadow DOM elements are loaded
I believe this is due to the fact that the shadow dom element is not loaded on the page at the time the...
Read more >Shadow DOM and events - The Modern JavaScript Tutorial
Events that happen in shadow DOM have the host element as the target, when caught outside of the component. Here's a simple example:....
Read more >Using shadow DOM - Web Components | MDN
Shadow DOM allows hidden DOM trees to be attached to elements in the regular DOM tree — this shadow DOM tree starts with...
Read more >5. Working with the Shadow DOM - Modern JavaScript [Book]
The shadow root is the root node for the shadow DOM branch. Shadow root child nodes are not returned by DOM queries even...
Read more >Shadow DOM v1 - Self-Contained Web Components
You don't have to author web components that use shadow DOM. But when you do, ... a shadow DOM ( <img> ). For...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm that is a tough one since
on-load
only watches thedocument.body
and AFAIK can’t observe mutations into shadow doms. We would need to observe the shadow root and there isn’t an interface provided for that.It would probably be expensive to detect whether an element is within a shadow dom, as we’d need to traverse the parentNode on render.
We might be able to have
on-load
watch for shadow doms added, then observe each of those as well. I have no idea if that would work or how expensive it would be though.this is no longer an issue with nanohtml because it doesn’t include
on-load
anymore.