Skip to content

fix: prevent panel unmount on extended tab inactivity#135

Merged
fx merged 3 commits intomainfrom
fix/panel-unmount-inactive-tab
Jul 13, 2025
Merged

fix: prevent panel unmount on extended tab inactivity#135
fx merged 3 commits intomainfrom
fix/panel-unmount-inactive-tab

Conversation

@fx
Copy link
Copy Markdown
Owner

@fx fx commented Jul 11, 2025

Summary

  • Enhanced the liebe-panel lifecycle management to prevent unmounting when tabs are inactive for extended periods
  • Added comprehensive logging to track panel lifecycle events
  • Implemented keep-alive mechanism that periodically touches the DOM and re-renders when needed
  • Added MutationObserver to detect and prevent removal from parent
  • Made panel initialization more robust to handle re-attachment scenarios

Problem

The liebe-panel was still being unmounted/removed by Home Assistant when the tab was inactive for extended periods (e.g., when the tab is not visible for a while). This was despite the previous fix in PR #132.

Solution

  1. Keep-Alive Mechanism: Added a periodic check (every 30 seconds) that:

    • Touches DOM properties to keep the element "active"
    • Re-renders the React app if the page has been inactive for more than 5 minutes
    • Updates interaction timestamps when the page becomes visible again
  2. MutationObserver: Implemented a parent observer that:

    • Detects when the panel is being removed from its parent
    • Attempts to re-add the panel if it has a valid hass object
  3. Enhanced Initialization:

    • Better detection of when re-initialization is needed
    • Checks for lost shadow root or React root
    • Prevents panel from being garbage collected by storing reference on window
  4. Comprehensive Logging: Added detailed logging throughout the lifecycle to help debug any future issues

Testing

  • Built the panel successfully with npm run build:ha
  • All TypeScript checks pass
  • All linting checks pass
  • All tests pass (463 tests)
  • Added extensive logging to monitor behavior in production

Related Issue

This addresses the ongoing issue where the panel disappears after extended periods of tab inactivity.

Previous Attempt

PR #132 addressed tab switching but didn't fully resolve the issue for extended inactive periods.

@fx fx merged commit c8bc464 into main Jul 13, 2025
2 checks passed
@fx fx deleted the fix/panel-unmount-inactive-tab branch July 13, 2025 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant