thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

Fix templates briefly rendering on page load #47

Closed ronaldheft closed 3 years ago

ronaldheft commented 3 years ago

When a page loads with a template entity row, you can sometimes briefly see the jinga2 template code before the template is rendered (fixes #16).

I came up with a solution to solve this rendering issue. I'm taking advantage of the logic already in place to hide the row and adding a check that all of the row's OPTIONS have been rendered (i.e. no longer pass the hasTemplate test). This ensures that before all of the jinga2 templates are interpreted the row will be hidden. Once all of the templates are interpreted, the row will appear into view without flickering the jinga2 template content.

I'm new to developing lovelace plugins, so there is perhaps a more efficient way to do this. Right now, I believe the check is being performed on every render. Since it's a simple loop, and hasTemplate is a simple string check, I'm assuming there will not be much of a performance penalty with adding this logic. Ideally, the check could be skipped once all templates are rendered, but I'm not sure how to best implement that at this moment within the lovelace card lifecycle.