When element is temporarily removed and then re appended to the dom styles from static get styles do not work. This only happens when browser supports constructible stylesheets. Manually calling this.shadowRoot!.adoptedStyleSheets = MyElement.styles.map(style => style.styleSheet) inside connectedCallback fixes the problem for that element but not for its children.
https://stackblitz.com/edit/typescript-vva73g?file=my-element.ts
my-elementmy-element to document.bodyStyles are still applied.
No styles from adoptedStyleSheets are applied.
Thanks for reporting this; it's a Chrome bug and has been filed here: https://bugs.chromium.org/p/chromium/issues/detail?id=934340.
Hopefully this issue will be fixed before the feature is released. If not, we'll add a workaround of some sort.
Can't open the Chrome issue, here is a minimal repro:
Minimal repro here: https://65s7tj-jqi1d9.stackblitz.io
Code at https://stackblitz.com/edit/65s7tj-jqi1d9
It's fixed in Chrome 74 canary, but broken in Chrome 73 beta, though I think the fix will be backported to 73 before it is released.
Looks like the fix was merged into 73. We should be seeing it roll out soon.
Most helpful comment
Looks like the fix was merged into 73. We should be seeing it roll out soon.