thomasloven / lovelace-card-mod

🔹 Add CSS styles to (almost) any lovelace card
MIT License
1.04k stars 169 forks source link

Still inconsistent behavior, not finding cause #354

Open tbrasser opened 5 months ago

tbrasser commented 5 months ago

My Home Assistant version: 2024.1.5 Frontend: 20240104.0

My lovelace configuration method (GUI or yaml): lovelace_gen

What I am doing: lots of card_mod and some mod-card usage.

What I expected to happen:

Card mod applying consistently:

Screenshot_2024-01-25-12-19-38-460_io.homeassistant.companion.android.jpg

What happened instead:

See screenshots:

Screenshot_2024-01-25-12-19-25-622_io.homeassistant.companion.android.jpg

I just noticed that at least on my desktop browser (where it also happens, and I was looking into the browser console) after a while (like more than a minute) the problem seems to go away, but only for that view.

Also the problem appears sometimes only on certain views and not in others (inconsistent which).

Minimal steps to reproduce:

Unsure, have tried clearing cache on affected devices. It doesn't seem to happen on ios companion app but does happen on my android 14 phone companion app and on tablets running fkb. Made sure all style keys are wrapped with card_mod:.

Here is my config: https://github.com/tbrasser/config

Error messages from the browser console:

Lots of this, but not sure if related:

VM2254:1 Uncaught (in promise) SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at s.<anonymous> (card-mod.js:1:48199)
    at d (card-mod.js:1:2813)
    at Generator.<anonymous> (card-mod.js:1:4159)
    at Generator.next (card-mod.js:1:3242)
    at y (card-mod.js:1:8728)
    at a (card-mod.js:1:8931)
    at card-mod.js:1:8990
    at new Promise (<anonymous>)
    at s.<anonymous> (card-mod.js:1:8871)
(anonymous) @ card-mod.js:1
d @ card-mod.js:1
(anonymous) @ card-mod.js:1
(anonymous) @ card-mod.js:1
y @ card-mod.js:1
a @ card-mod.js:1
(anonymous) @ card-mod.js:1
(anonymous) @ card-mod.js:1
(anonymous) @ card-mod.js:1
(anonymous) @ card-mod.js:1
Ge @ card-mod.js:1
setTimeout (async)
(anonymous) @ card-mod.js:1
(anonymous) @ core.86iHY1cTxXI.js:1
_handleMessage @ core.86iHY1cTxXI.js:1

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

Important note I forgot to add, closing companion app and starting it again always solves it, and it comes back only after I left the dashboard (different app or for example home assistant settings). Same on fsk, reloading start url works, albeit temporarily.

broyuken commented 5 months ago

I'm having similar issues, I have a config that will center text in a picture-elements card that only sometimes works. Sometimes it centers the text, sometimes it defaults to left aligned. Here is my card config. All I do to "fix" it is refresh multiple times and 1/5 times it will display correctly. Happens on the web, and in the app. Cleared cache, reinstalled apps, nothing seems to make it consistently work.

type: picture-elements
elements:
  - type: conditional
    conditions:
      - entity: person.brian
        state_not: home
    elements:
      - type: image
        entity: person.brian
        image: local/media/images/PeopleImages/Brian.jpg
        style:
          top: 50%
          left: 50%
          width: 100%
          height: 100%
          filter: saturate(30%)
  - type: conditional
    conditions:
      - entity: person.brian
        state: not_home
    elements:
      - type: image
        entity: person.brian
        image: local/media/images/PeopleImages/Brian.jpg
        style:
          top: 50%
          left: 50%
          width: 100%
          height: 100%
          filter: saturate(0)
  - type: image
    entity: person.brian
    image: local/media/images/PeopleImages/person_background.png
    style:
      top: 50%
      left: 50%
      width: 100%
      height: 100%
      opacity: 0.5
  - type: state-label
    entity: sensor.places_brian
    style:
      top: 81%
      left: 50%
      width: 100%
      color: white
      font-size: 1.2em
    card_mod:
      style: |
        div {
          white-space: unset !important;
          text-align: center !important;
        }
  - type: conditional
    conditions:
      - entity: person.brian
        state_not: home
    elements:
      - type: state-label
        entity: sensor.brians_iphone_travel_time
        suffix: ' from home'
        style:
          top: 96%
          left: 50%
          color: white
          font-size: 1.0em
image: local/media/images/PeopleImages/Brian.jpg

This is how it looks when it's broken. image

And this is how it looks when it works right. image

broyuken commented 5 months ago

What would mine look like after changing it? I don't see anything to really change in my example. Also, I did enable card mod as an extra module in configuration.yaml but that didn't fix it either.

broyuken commented 5 months ago

ok, so I just realized that I can set the style's directly in the picture elements card, so I no longer need card mod for this use case. My issue is resolved simply by putting the text-align directly under the style: section instead of inside card-mod.

tbrasser commented 5 months ago

Also no idea where in my lovelace / theme I'd apply that conversion, seems I already do that.

A couple of things I found:

card_mod:
  class: invisible
  style: |
    ha-card: { something: 42px; }
    .:
      ha-card { otherthing: -42px; } 
mainTAP commented 3 months ago

I'm also having issues with card-mod, I'm only changing colors of icons but sometimes it doesn't work and the page needs to be refreshed a few times.

                  card_mod:
                    style: |
                      :host {
                        --paper-item-icon-color: #984ea3;
                      }
rubin110 commented 1 month ago

I'm still hitting this issue with 3.4.3. Downgrading to 3.4.1 doesn't help. So first off I believe that #85 and #346 are related.

I can consistently repro this via Chrome by having the console open in the Chrome debugger and doing a ctrl+shift+r hard reload (or with the debugger open right click on the refresh button next to the address bar). If anyone else can confirm that would be awesome.

Looking at the console output I can see that when the issue is reproed CARD-MOD 3.4.3 IS INSTALLED shows up much later, than when the issue isn't present. So this seems to be some sort of race condition.

I have around 35 HACS frontend resources loaded. I reduced that down to 28. The issue is happening slightly less frequently but still present.

julienaltieri commented 1 month ago

I'm also encountering this issue on the companion app on Android. This was happening on desktop as well but solved after I followed the recommendation to load card-mod.js as a frontend module. On the companion app, I've tried clearing the cache, ensuring the app is up-to-date, and I also confirmed that when I access HA from mobile chrome, it works as expected.

Edit: I noticed that the problem goes away when I clear the cache of the Android Webview app under Apps > AndroidWebview > Storage usage Maybe this is what I was missing after changing to a frontend module