From 134ed7d303c9065243ac2fc86443de0336927117 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 10 Feb 2022 00:14:25 +0100 Subject: [PATCH] Only load ha-selector when needed (#11630) --- src/components/ha-form/ha-form.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/ha-form/ha-form.ts b/src/components/ha-form/ha-form.ts index 100dadc2b7..15293808e8 100644 --- a/src/components/ha-form/ha-form.ts +++ b/src/components/ha-form/ha-form.ts @@ -1,4 +1,4 @@ -import { css, CSSResultGroup, html, LitElement } from "lit"; +import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; import { dynamicElement } from "../../common/dom/dynamic-element-directive"; import { fireEvent } from "../../common/dom/fire_event"; @@ -11,12 +11,13 @@ import "./ha-form-multi_select"; import "./ha-form-positive_time_period_dict"; import "./ha-form-select"; import "./ha-form-string"; -import "../ha-selector/ha-selector"; import { HaFormElement, HaFormDataContainer, HaFormSchema } from "./types"; import { HomeAssistant } from "../../types"; const getValue = (obj, item) => (obj ? obj[item.name] : null); +let selectorImported = false; + @customElement("ha-form") export class HaForm extends LitElement implements HaFormElement { @property() public hass!: HomeAssistant; @@ -46,6 +47,19 @@ export class HaForm extends LitElement implements HaFormElement { } } + willUpdate(changedProperties: PropertyValues) { + super.willUpdate(changedProperties); + if ( + !selectorImported && + changedProperties.has("schema") && + this.schema && + this.schema.some((item) => "selector" in item) + ) { + selectorImported = true; + import("../ha-selector/ha-selector"); + } + } + protected render() { return html`