Skip to content

Commit 3980e85

Browse files
authored
fix(adopt-root-styles): preserve rules and overrides order (#2105)
1 parent 06b528e commit 3980e85

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/components/chat/chat.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,11 @@ describe('Chat', () => {
10711071
const styles = document.createElement('style');
10721072
styles.setAttribute('id', 'adopt-styles-test');
10731073
styles.innerHTML = `
1074+
.custom-background {
1075+
background-color: rgb(255, 255, 0);
1076+
}
1077+
1078+
/* override */
10741079
.custom-background {
10751080
background-color: rgb(255, 0, 0);
10761081
}

src/components/common/controllers/adopt-styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class AdoptedStylesController implements ReactiveController {
172172
}
173173

174174
try {
175-
constructed.insertRule(rule.cssText);
175+
// insert last to keep rules/override order:
176+
constructed.insertRule(rule.cssText, constructed.cssRules.length);
176177
hasRules = true;
177178
} catch {
178179
// Skip rules that cannot be cloned (e.g., invalid syntax)

0 commit comments

Comments
 (0)