Skip to content

Commit 28d8a07

Browse files
committed
fix(theme): prevent property sets attribute set property stack overflow
1 parent 3c3b634 commit 28d8a07

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/theme/src/theme.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
7272
old: string | null,
7373
value: string | null
7474
): void {
75+
if (old === value) {
76+
return;
77+
}
7578
if (attrName === 'color') {
7679
this.color = value as Color;
7780
} else if (attrName === 'scale') {
@@ -109,14 +112,15 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
109112
!!newValue && ColorValues.includes(newValue)
110113
? newValue
111114
: this.color;
115+
if (color !== this._color) {
116+
this._color = color;
117+
this.requestUpdate();
118+
}
112119
if (color) {
113120
this.setAttribute('color', color);
114121
} else {
115122
this.removeAttribute('color');
116123
}
117-
if (color === this._color) return;
118-
this._color = color;
119-
this.requestUpdate();
120124
}
121125

122126
private _scale: Scale | '' = '';
@@ -134,14 +138,15 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
134138
!!newValue && ScaleValues.includes(newValue)
135139
? newValue
136140
: this.scale;
141+
if (scale !== this._scale) {
142+
this._scale = scale;
143+
this.requestUpdate();
144+
}
137145
if (scale) {
138146
this.setAttribute('scale', scale);
139147
} else {
140148
this.removeAttribute('scale');
141149
}
142-
if (scale === this._scale) return;
143-
this._scale = scale;
144-
this.requestUpdate();
145150
}
146151

147152
private get styles(): CSSResult[] {

0 commit comments

Comments
 (0)