usernein / tailwindcss-template-card

Custom card for Home Assistant that renders html code with TailwindCSS styles into the dashboard
MIT License
48 stars 1 forks source link

Constant Refreshing #1

Closed luixal closed 10 months ago

luixal commented 10 months ago

Hi,

As other user has noticed in the community page thread, this card seems to be continously resfreshing.

I think the problem can be here, as this comparison will always evaluate to false if attributes is an object (which I think it is):

this._oldHass.states[entity_id].attributes !== this._hass.states[entity_id].attributes

I'm also not sure about this other comparison, as I think the hass object always contains all entities whenever one of them changes:

this._oldHass.states[entity_id] !== this._hass.states[entity_id]

I've trying this card and is awesome, but this continous refresh is causing performance issues in my wall panels which are always showing the dashboard. Would be nice to have it fixed :)

Maybe it would be simpler watching only entities in the entity and entities fields, not looking into the content to find them.

Thanks for your great work!

PS: if you add some steps about how to compiling and testing this card I can give it a try :)

usernein commented 10 months ago

Hello there! Thanks for posting this issue and thanks for your analysis!

I actually thought at first that i had fixed it :v But obviously that's not the case.

Since my last contribution on this project, i learned a lot about how useContext affects React performance causing re-renders and i am pretty sure that's the culprit, together with some other minor errors like comparison of objects (i am used to Python's behavior, which is far different from JavaScript's behavior).

I'll do a huge refactor on tailwindcss-template-card today, putting together everything that i learned in the recent months. I'll keep you posted about it!

usernein commented 10 months ago

Hello! Can you try v3.1.1 and check if the constant refreshes still happen?

For me, it seems that it works just fine now, not refreshing on every state change

https://github.com/usernein/tailwindcss-template-card/assets/29507335/eeba590d-8768-46da-819b-3e8a3196998e

luixal commented 10 months ago

Hi,

I just tried it out and it seems to be fixed, thanks! :)

Just for you to know, I realized it was constantly refreshing when I add some css to change card's background using card mod like this:

style: |
  ha-card {
    background-color: red;
  }

Using that, you could see the red background constantly flickering. Also, this card in a 24/7 wallpanel made the system really clonky after a couple days due to memory issues. That's why I started looking into your code to see what could be going on :)

Anyway, now, it's working great.