Skip to content

Fix Lovelace view background flicker when switching between views with identical backgrounds#51371

Open
tw-zs wants to merge 3 commits intohome-assistant:devfrom
tw-zs:fix-background-flicker
Open

Fix Lovelace view background flicker when switching between views with identical backgrounds#51371
tw-zs wants to merge 3 commits intohome-assistant:devfrom
tw-zs:fix-background-flicker

Conversation

@tw-zs
Copy link
Copy Markdown

@tw-zs tw-zs commented Apr 2, 2026

Proposed change

This PR fixes an issue where switching between views with background images causes the background to flicker/flash white or black.

The flicker occurs because:

  1. The <hui-view-background> component was a child of <hui-view-container> and was being removed/recreated on every view switch
  2. Even when using the same background image, _fetchMedia() was being called unnecessarily

This PR addresses both issues:

Fix 1: Move hui-view-background outside hui-view-container

The <hui-view-background> component is now a sibling of <hui-view-container> instead of a child. This prevents it from being removed when switching views, eliminating the flicker caused by component recreation.

Fix 2: Cache resolved media sources and skip unnecessary updates

  • Added mediaSourceUrlCache to cache resolved media source URLs
  • Added _currentMediaContentId to track the currently loaded image
  • Added _pendingMediaContentId to track in-flight media resolution
  • Added deepEqual comparison to skip updates when background config is unchanged
  • Added CSS transition for smoother background changes

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Code quality improvements

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the development checklist

Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tw-zs

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft April 2, 2026 11:25
@home-assistant
Copy link
Copy Markdown

home-assistant bot commented Apr 2, 2026

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

…-container

This change moves the hui-view-background component outside of
hui-view-container so it is not removed when switching views.
Previously, hui-view-background was a child of hui-view-container
and was being recreated on every view switch, causing a white/black
flash when switching between views with backgrounds.

Changes:
- Move hui-view-background to be a sibling of hui-view-container
- Add fixed positioning CSS for hui-view-background
- Simplify component styles to remove redundant positioning
- Add CSS transition for smooth background changes

Fixes home-assistant#51300
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tw-zs

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@tw-zs tw-zs marked this pull request as ready for review April 2, 2026 11:26
@home-assistant home-assistant bot dismissed stale reviews from themself April 2, 2026 11:26

Stale

@piitaya piitaya self-assigned this Apr 2, 2026
Copy link
Copy Markdown
Member

@piitaya piitaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi 👋

The background element is now always position: fixed (set by the parent), whereas before it used position: absolute for non-fixed backgrounds and position: fixed only for fixed ones (Safari iOS hack : #22531).

I tested and the scroll behavior is broken (even in chrome) when using attachment: scroll

Comment on lines +1494 to +1501
hui-view-background {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background is always fixed now. This means attachment: scroll doesn't work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background image flickers (white/black screen flash) when switching between dashboard views

2 participants