Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying a theme causes a flood of exceptions in the developer console. #436

Open
4 tasks done
okets opened this issue Jan 15, 2025 · 0 comments
Open
4 tasks done

Comments

@okets
Copy link

okets commented Jan 15, 2025

My Home Assistant version: 2025.1.2

My lovelace configuration method (GUI or yaml): YAML & GUI

What I am doing: Change themes programmatically in one of my custom cards

What I expected to happen:
not to spam the console with errors.
What happened instead:
the console is spammed with errors.

Minimal steps to reproduce:
change the theme dynamically using a button that calls "setTheme"
this is a code for the button:

const ev = new Event("settheme", {
	bubbles: true,
	cancelable: false,
	composed: true,
});
ev.detail = { theme: "my-theme" }
this.dispatchEvent(ev);
# The least amount of code possible to reproduce my error
The problem has nothing to do with YAML, it happens whenever the theme is changed programmatically.
# End of code

Error messages from the browser console:
Uncaught (in promise) SyntaxError: "undefined" is not valid JSON
I have debugged it and figured out the source of the error.
in the constructor you call:

document.addEventListener("cm_update", () => {
    this._process_styles(this.card_mod_input);
});

in order to prevent this bug, I capture the event myself and stopPropagation so your event listener will not pop.

the bug occurs even after removing all card_mod instructions, just having card-mod installed and changing themes dynamically is enough.

By putting an X in the boxes ([]) below, I indicate that I:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant