Skip to content

Commit b2c488a

Browse files
fix(chat): adoptRootStyles @import rules interaction (#1931)
Since `@import` was officially dropped from the specfication for constructed style sheets, skip trying to insert any such CSS rules and error out, preventing adopting the rest of the rules inside the chat message. Co-authored-by: Galina Edinakova <[email protected]>
1 parent 30af490 commit b2c488a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/components/chat/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ export function isImageAttachment(
110110
);
111111
}
112112

113-
// REVIEW: Maybe put that behind a configuration flag as this is nasty.
114113
export function chatMessageAdoptPageStyles(
115114
message: IgcChatMessageComponent
116115
): void {
@@ -120,6 +119,10 @@ export function chatMessageAdoptPageStyles(
120119
try {
121120
const constructed = new CSSStyleSheet();
122121
for (const rule of sheet.cssRules) {
122+
// https://drafts.csswg.org/cssom/#dom-cssstylesheet-insertrule:~:text=If%20parsed%20rule%20is%20an%20%40import%20rule
123+
if (rule.cssText.startsWith('@import')) {
124+
continue;
125+
}
123126
constructed.insertRule(rule.cssText);
124127
}
125128
sheets.push(constructed);

0 commit comments

Comments
 (0)