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

Wait until hass initialized before merging card and theme styles #284

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

akomelj
Copy link

@akomelj akomelj commented Jun 5, 2023

This pull request may fix issues described in #152 (in some cases).

I experienced similar behavior - styles not being applied after page refresh - on one of my dashboards. I suspect some race condition occurs when card-mod styles are being applied as styles are correctly applied on some of my dashboards and randomly on others.

Please note that I am using a custom card-mod theme and the missing styles are set globally in the theme.

I noticed that sometimes card-mod did not read value of CSS variable --card-mod-theme correctly when debugging the issue. Moving await hass() in front of getPropertyValue("--card-mod-theme") appears to block the app for just enough time that variable --card-mod-theme is being set and can be read by card-mod.

It is quite possible that this is not a definite fix for #152. await hass() call postpones variable read for a few ticks and this may suffice in my particular case - refreshing page now works in 100% of my cases. YMMV.

src/helpers.ts Outdated
@@ -168,9 +173,9 @@ export function getResources() {
const retval = [];
for (const script of scriptElements) {
if (script?.innerText?.trim()?.startsWith("import(")) {
const imports = script.innerText.split("\n")?.map((e) => e.trim());
const imports = script.innerText.split(/[\n;]/)?.map((e) => e.trim()).filter(e => e);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part seems unrelated

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yes, you are correct. This was a one-liner fix that was later implemented in #278 and is not needed here. I pushed another commit reverting this change.

@akomelj
Copy link
Author

akomelj commented Dec 3, 2023

Hi, maybe this will help. I might be spreading misinformation but it´s 100% consistent for me.

Unfortunately this does not work for me. I do not experience this behaviour with card-embedded styles; my beef is with global styles that are defined in custom Home Assistant theme.

Here - in my case - the problem is the missing value of --card-mod-theme CSS variable and the styles not being applied due to this.

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

Successfully merging this pull request may close these issues.

2 participants