Skip to content

Commit 251c41e

Browse files
authored
fix: prevent panel from disappearing when switching tabs (#132)
1 parent e2ac74f commit 251c41e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/panel.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ import '~/styles/app.css'
1818
class LiebePanel extends HTMLElement {
1919
private _hass: HomeAssistant | null = null
2020
private root?: ReactDOM.Root
21+
private initialized = false
2122

2223
set hass(hass: HomeAssistant) {
2324
this._hass = hass
2425
this.render()
2526
}
2627

2728
connectedCallback() {
28-
if (!this.root) {
29+
// Only initialize once - don't recreate on reconnection
30+
if (!this.initialized) {
31+
this.initialized = true
32+
2933
const shadow = this.attachShadow({ mode: 'open' })
3034
const container = document.createElement('div')
3135
container.style.height = '100%'
@@ -49,11 +53,13 @@ class LiebePanel extends HTMLElement {
4953

5054
this.root = ReactDOM.createRoot(container)
5155
}
56+
5257
this.render()
5358
}
5459

5560
disconnectedCallback() {
56-
this.root?.unmount()
61+
// Do NOT unmount or cleanup - Home Assistant will re-add this element
62+
// when the user navigates back to the panel
5763
}
5864

5965
private render() {

0 commit comments

Comments
 (0)