Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mistyharsh/98f1c35a64250bd8903c0c9cdff43ed9 to your computer and use it in GitHub Desktop.
Save mistyharsh/98f1c35a64250bd8903c0c9cdff43ed9 to your computer and use it in GitHub Desktop.
// Create style node outside of WebComponent
const style = document.createElement('style');
style.innerHTML = `
p { color: blue; }
`;
class FancyComponent extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = `
<div>
<p>Hello World</p>
</div>
`;
// Let us try to optimize
// Deep cloning of style node
const clonedStyle = style.cloneNode(true);
shadowRoot.appendChild(clonedStyle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment