Skip to content

Commit e2707dd

Browse files
authored
fix(lit): replace unsafeCSS with CSSStyleSheet for structural styles (#633)
* fix(lit): replace unsafeCSS with CSSStyleSheet for structural styles * chore(lit): log structural stylesheet construction failures and simplify fallback path * fix(lit): fail fast on browser structural stylesheet errors and no-op in non-browser runtime
1 parent 99c743e commit e2707dd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

renderers/lit/src/0.8/ui/styles.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,21 @@
1414
limitations under the License.
1515
*/
1616

17-
import { unsafeCSS } from "lit";
17+
import type { CSSResultGroup } from "lit";
1818
import * as Styles from "@a2ui/web_core/styles/index";
1919

20-
export const structuralStyles = unsafeCSS(Styles.structuralStyles);
20+
const buildStructuralStyles = (): CSSResultGroup => {
21+
if (typeof window === "undefined") {
22+
return [];
23+
}
24+
25+
try {
26+
const styleSheet = new CSSStyleSheet();
27+
styleSheet.replaceSync(Styles.structuralStyles);
28+
return styleSheet;
29+
} catch (e) {
30+
throw new Error("Failed to construct structural styles.", { cause: e });
31+
}
32+
};
33+
34+
export const structuralStyles = buildStructuralStyles();

0 commit comments

Comments
 (0)