aboutsummaryrefslogtreecommitdiff
path: root/src/server-component.mjs
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-06-16 10:10:57 +0100
committerHayleigh Thompson <me@hayleigh.dev>2024-06-16 10:10:57 +0100
commita924297b13039e752c6bbd12d9a8ee429a2d4e63 (patch)
tree7d529cb210b6e38948a7ba69fc7a8058a35522a7 /src/server-component.mjs
parent57fb60de92c81e4e344f8109d51ea2d1a4996bd0 (diff)
downloadlustre-a924297b13039e752c6bbd12d9a8ee429a2d4e63.tar.gz
lustre-a924297b13039e752c6bbd12d9a8ee429a2d4e63.zip
:recycle: Inherit component styles by cloning link/style tags.
Diffstat (limited to 'src/server-component.mjs')
-rw-r--r--src/server-component.mjs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/server-component.mjs b/src/server-component.mjs
index 31cd364..d4cb4a9 100644
--- a/src/server-component.mjs
+++ b/src/server-component.mjs
@@ -49,19 +49,18 @@ export class LustreServerComponent extends HTMLElement {
}
connectedCallback() {
- this.#root = document.createElement("div");
- this.#shadow.appendChild(this.#root);
-
- const sheet = new CSSStyleSheet();
-
- for (const { cssRules } of document.styleSheets) {
- for (const rule of cssRules) {
- console.log(rule);
- sheet.insertRule(rule.cssText);
+ for (const link of document.querySelectorAll("link")) {
+ if (link.rel === "stylesheet") {
+ this.#shadow.appendChild(link.cloneNode(true));
}
}
- this.#shadow.adoptedStyleSheets = [sheet];
+ for (const style of document.querySelectorAll("style")) {
+ this.#shadow.appendChild(style.cloneNode(true));
+ }
+
+ this.#root = document.createElement("div");
+ this.#shadow.appendChild(this.#root);
}
attributeChangedCallback(name, prev, next) {