Skip to content

Commit

Permalink
fix(theme): prevent property sets attribute set property stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Jun 8, 2020
1 parent 3c3b634 commit 28d8a07
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/theme/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
old: string | null,
value: string | null
): void {
if (old === value) {
return;
}
if (attrName === 'color') {
this.color = value as Color;
} else if (attrName === 'scale') {
Expand Down Expand Up @@ -109,14 +112,15 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
!!newValue && ColorValues.includes(newValue)
? newValue
: this.color;
if (color !== this._color) {
this._color = color;
this.requestUpdate();
}
if (color) {
this.setAttribute('color', color);
} else {
this.removeAttribute('color');
}
if (color === this._color) return;
this._color = color;
this.requestUpdate();
}

private _scale: Scale | '' = '';
Expand All @@ -134,14 +138,15 @@ export class Theme extends HTMLElement implements ThemeKindProvider {
!!newValue && ScaleValues.includes(newValue)
? newValue
: this.scale;
if (scale !== this._scale) {
this._scale = scale;
this.requestUpdate();
}
if (scale) {
this.setAttribute('scale', scale);
} else {
this.removeAttribute('scale');
}
if (scale === this._scale) return;
this._scale = scale;
this.requestUpdate();
}

private get styles(): CSSResult[] {
Expand Down

0 comments on commit 28d8a07

Please sign in to comment.