lovelace-card-mod: card-mod code may be not saved in UI editor - or just auto-deleted after typing - or may not be shown in editor
Chrome 120.0.6099.130 (Win10x64). FF 121 (Win10x64).
My Home Assistant version: 2023.12.1
My lovelace configuration method (GUI or yaml): storage
What I am doing:
Adding card-mod code for custom:bar-card inside a standard vertical-stack.
Using a standard HA UI editor.
What I expected to happen: Card-mod code is saved after saving a card.
What happened instead:
- Either card-mod code is not saved after saving a card.
- Or card-mod code is automatically deleted after typing.
Minimal steps to reproduce:
- Add a new card - select any card like “Alarm card”.
- Switch to yaml editor.
- Paste a code provided below.
- Start typing “card_mod” for the “bar-card”.
- If you manage to type the “card_mod” line - then type the whole card-mod code (see below).
- Save the card.
- Reopen the card in the Editor.
- Check that card-mod code was deleted.
- Start typing card-mod again.
- Check that “card_mod” line is auto-deleted after typing.
type: vertical-stack
cards:
- type: custom:bar-card
entities:
- entity: sensor.processor_use
type: vertical-stack
cards:
- type: custom:bar-card
entities:
- entity: sensor.processor_use
card_mod:
style: |
ha-card {color: red;}
Error messages from the browser console: none related.
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.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 10
- Comments: 65 (21 by maintainers)
I am actively looking into the cuase of this issue. The root cause would appear to be two copies of card-mod running, with multiple patching of home assistant elements. In such a case of card with
entities:card mod does some patching to removecard_mod:section, apply the unpatched card config update, then add backcard_mod:config. Id the patching is happening twice, this will meancard_mod:not showing on edit in yaml (but still in yaml, just not showing), as teh first patch has removed it, so the second patch won’t add anything back. From what I see this specific issue will only effect cards withentities:, including custom cards likecustom:bar-card.How to mitigate?
From my testing (Chrome on Mac OS), having URLs in Dashboard resources and Frontend module URL which are not EXACTLY the same results in card-mod JS being ‘loaded’ twice but the usual mechanism to not add the custom card again seems to break for some browsers. Can’t replicate this directly so it must be to do with timing, caching ?? [Anyone interesed can easily add console log messages at the end of card-mod.ts to validate this assertion]
I know I have suggsted this in the past, and some say it doesn’t matter, but my testing shows different. So it is recommend to either.
NOTE: I am still actively looking into how multiple pacthing of elements may take place. It is my opinion that the above is valid and workaround recommended. However, if anyone has anything more to contribute, please do. 🙏
I am having the same problem. When the code is not shown again when reopening the editor, if I save it strips the previously saved card-mod changes.
However, I am a novice with Card Mod. I do not use the “|” after styles. My previously-working code did not require it:
If I use that on a card, it works as expected. When I edit the card it disappears. When I save it reverts to unmodded.
edit: It appears that cards with edited card-mod code is stripped from the editor upon reload. Card-mod code saved prior to the latest version, and left unedited, does NOT appear to be stripped upon reload.
I am now forced to edit the cards in the raw configuration editor. Quite the pain to find the code in a large dashboard. I have it both as a resource and “extra_module_url” if that makes any difference. Also noticed that this only happens when a card opens to the visual editor, if a card does not have a visual editor it shows correctly. I am also in the Home Assistant beta path, perhaps that is a contributing reason?
For me this issue occured because of ui-lovelace-minimalist. It also injects card-mod internally (as lovelace-card-mod.js). If you also install card-mod separately, it causes the card-mod code to be injected twice, triggering the bug. So i removed card-mod and it’s good for now.
Can confirm, this workaround works after clearing browser/mobile cache. Hopefully, this prolonged bug is resolved soon.
The real issue seems to be in adding the extra modules line for card mod in configuration.yaml. Afaik 3.4.4 should also work if you remove that line
If you manage to save your card-mod code - it is really saved in json:
And the style is applied:
But the Editor does not show card-mod code:
I get it, but I also think it is good to use something that actually shows on the screen. Anyway - good luck with solving your issue.
Same thing. In
storagemode, editing card mod styles works fine using Show Code Editor, but the card mod is lost immediately when using the Visual Editor. It’s not lost on save, but immediately when the card is selected.See the card mods applied to badges in the following videos and how they go white as soon as the card is selected.
Mushroom cards Core 2024.3.1 Frontend 20240307.0 card-mod 3.4.2
With
extra_module_urlconfiguredhttps://github.com/thomasloven/lovelace-card-mod/assets/2578772/1a5a2747-c76e-4d12-9ff3-aa27abfda27c
Removing
extra_module_urlappears to resolve the problemhttps://github.com/thomasloven/lovelace-card-mod/assets/2578772/650e73ed-db69-4f30-ae44-caa28bd89bf8
It looks like it has to do with
card-mod.jsbeing included twice. When I remove either the one from resources or the one underextra_module_urlit works fine.@OmegaPrime90 Your code is absolutely wrong & could be confusing for other beginners.