mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 02:06:42 +00:00
Fix race in theme setting (#9027)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
542f169b36
commit
1904c4d057
@ -22,6 +22,8 @@ const mql = matchMedia("(prefers-color-scheme: dark)");
|
|||||||
|
|
||||||
export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||||
class extends superClass {
|
class extends superClass {
|
||||||
|
private _themeApplied = false;
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this.addEventListener("settheme", (ev) => {
|
this.addEventListener("settheme", (ev) => {
|
||||||
@ -32,7 +34,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
storeState(this.hass!);
|
storeState(this.hass!);
|
||||||
});
|
});
|
||||||
mql.addListener((ev) => this._applyTheme(ev.matches));
|
mql.addListener((ev) => this._applyTheme(ev.matches));
|
||||||
if (mql.matches) {
|
if (!this._themeApplied && mql.matches) {
|
||||||
applyThemesOnElement(
|
applyThemesOnElement(
|
||||||
document.documentElement,
|
document.documentElement,
|
||||||
{
|
{
|
||||||
@ -51,6 +53,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
|||||||
super.hassConnected();
|
super.hassConnected();
|
||||||
|
|
||||||
subscribeThemes(this.hass!.connection, (themes) => {
|
subscribeThemes(this.hass!.connection, (themes) => {
|
||||||
|
this._themeApplied = true;
|
||||||
this._updateHass({ themes });
|
this._updateHass({ themes });
|
||||||
invalidateThemeCache();
|
invalidateThemeCache();
|
||||||
this._applyTheme(mql.matches);
|
this._applyTheme(mql.matches);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user