diff --git a/src/panels/config/helpers/forms/ha-schedule-form.ts b/src/panels/config/helpers/forms/ha-schedule-form.ts index f38c36b3ba3f..a1c08c083e6b 100644 --- a/src/panels/config/helpers/forms/ha-schedule-form.ts +++ b/src/panels/config/helpers/forms/ha-schedule-form.ts @@ -93,6 +93,20 @@ class HaScheduleForm extends LitElement { } } + public disconnectedCallback(): void { + super.disconnectedCallback(); + this.calendar?.destroy(); + this.calendar = undefined; + this.renderRoot.querySelector("style[data-fullcalendar]")?.remove(); + } + + public connectedCallback(): void { + super.connectedCallback(); + if (this.hasUpdated && !this.calendar) { + this.setupCalendar(); + } + } + public focus() { this.updateComplete.then( () => @@ -165,6 +179,10 @@ class HaScheduleForm extends LitElement { } protected firstUpdated(): void { + this.setupCalendar(); + } + + private setupCalendar(): void { const config: CalendarOptions = { ...defaultFullCalendarConfig, locale: this.hass.language,