question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Style gone after page refresh

See original GitHub issue

My Home Assistant version: core-2021.11.1

My lovelace configuration method (GUI or yaml): GUI

What I am doing: Using card-mod to apply different colors to badges based on availability (home / not home)

  - entity: device_tracker.82_98_86_f8_67_aa
    card_mod:
      style: |
        :host {
          --label-badge-red: {% if is_state('device_tracker.82_98_86_f8_67_aa', 'home') %} green {% else %} grey {% endif %};
        } 
  - entity: device_tracker.18_01_f1_4a_a0_52
    style: |
      :host {
        --label-badge-red: {% if is_state('device_tracker.18_01_f1_4a_a0_52', 'home') %} green {% else %} grey {% endif %};
      } 

What I expected to happen: See different colors for badges

image

image

After page refresh in browser style is gone. badges are just red:

image

What happened instead: Correct colors are sometimes visible but after a page refresh they are just red. Happens with Edge, Chrome and on Android Mobile.

Minimal steps to reproduce:

# The least amount of code possible to reproduce my error

      - entity: device_tracker.82_98_86_f8_67_aa
        card_mod:
          style: |
            :host {
              --label-badge-red: {% if is_state('device_tracker.82_98_86_f8_67_aa', 'home') %} green {% else %} grey {% endif %};
            } 
      - entity: device_tracker.18_01_f1_4a_a0_52
        style: |
          :host {
            --label-badge-red: {% if is_state('device_tracker.18_01_f1_4a_a0_52', 'home') %} green {% else %} grey {% endif %};
          } 

# End of code

Error messages from the browser console:

card-mod.js?hacstag=1909275243013:1

   The main 'lit-element' module entrypoint is deprecated. Please update your imports to use the 'lit' package: 'lit' and 'lit/decorators.ts' or import from 'lit-element/lit-element.ts'. See https://lit.dev/msg/deprecated-import-path for more information.

(anonym) @ card-mod.js?hacstag=1909275243013:1


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

  • Understand that this is a channel for reporting bugs, not a support forum (https://community.home-assistant.io/).

  • Have made sure I am using the latest version of the plugin.

  • Have followed the troubleshooting steps of the “Common Problems” section of https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins.

  • Understand that leaving one or more boxes unticked or failure to follow the template above may increase the time required to handle my bug-report, or cause it to be closed without further action.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
tabnulcommented, Nov 22, 2021

I had exact this issue , sometimes the style was applied, sometimes not. When i edited the style, and stayed in the ‘edit dashboard view’ all was fine. After i went back to the normal view (click cross) it went wrong.

I got it structurally fixed after installing 3.1.0 and making sure the performance improvement setting is set correctly, for HACS:

frontend:
  extra_module_url:
    - /hacsfiles/lovelace-card-mod/card-mod.js
0reactions
Kedryncommented, Feb 15, 2022

I’m experiencing exact same problem. Some cards gets the right colors when refreshing, some don’t, but in the code edit windows, colors are always applied.

HA 2022.2 and card_mod 3.1.2

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page controls lose style after page reload - Stack Overflow
I've noticed sometimes Kendo styling will end up overriding some of my stylesheets. First thing I'd do is add !important to your styles...
Read more >
style disappearing on hard refresh / new load with nextJS #2226
Navigating to the page would keep the styles, but a refresh / hot reload would cause one box that contained a background on...
Read more >
How to Save State to LocalStorage & Persist on Refresh with ...
If we open our developer tools and go to the Application tab (in Chrome) and open the Local Storage section along with our...
Read more >
location.reload() - Web APIs | MDN
The location.reload() method reloads the current URL, like the Refresh button. The reload may be blocked and a SECURITY_ERROR DOMException ...
Read more >
How to reload CSS without reloading the page using JavaScript
Syntax: Add the created CSS file like the below format. · index. · CSS file style. · Output: · You can add this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found