1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-17 23:54:28 +01:00

Propagate schema changes to existing form editor element (#30200)

* Re-create form editor when schema changes in hui-form-element-editor

When a parent component passes a new schema to hui-form-element-editor
(e.g. with updated disabled flags after an entity change), the internal
hui-form-editor was not rebuilt because loadConfigElement() short-circuits
once the config element exists. This meant dynamic schema changes were
silently ignored.

Override updated() to detect schema changes after initial load, tear down
the stale config element via unloadConfigElement(), and re-set the value
so the normal load path recreates the form with the current schema.

Fixes #29776

* Fix prettier formatting in hui-map-card.ts

Pre-existing formatting issue on dev branch.

* Propagate schema changes to existing form editor element

When the schema property on hui-form-element-editor changes (e.g. because
the selected entity changed and disabled flags need updating), directly
update the schema on the already-created hui-form-editor config element.

Previously, unloadConfigElement() was tried but caused a visible flash
(editor going blank then reappearing), and re-setting value with a spread
object was tried but deepEqual considers it unchanged, short-circuiting
the reload.

The fix is minimal: make _configElement protected in HuiElementEditor so
the subclass can reach it, then in the updated() hook push the new schema
directly onto the existing element — no teardown, no re-creation.
This commit is contained in:
Petar Petrov
2026-03-22 10:40:31 +01:00
committed by GitHub
parent 2fec5a497e
commit 77ee966442
2 changed files with 13 additions and 1 deletions

View File

@@ -62,7 +62,7 @@ export abstract class HuiElementEditor<
@state() private _config?: T;
@state() private _configElement?: LovelaceGenericElementEditor;
@state() protected _configElement?: LovelaceGenericElementEditor;
@state() private _subElementEditorConfig?: SubElementEditorConfig;

View File

@@ -1,6 +1,8 @@
import type { PropertyValues } from "lit";
import { customElement, property } from "lit/decorators";
import type { HaFormSchema } from "../../../components/ha-form/types";
import type { LovelaceConfigForm } from "../types";
import type { HuiFormEditor } from "./config-elements/hui-form-editor";
import { HuiElementEditor } from "./hui-element-editor";
@customElement("hui-form-element-editor")
@@ -10,6 +12,16 @@ export class HuiFormElementEditor extends HuiElementEditor {
protected async getConfigForm(): Promise<LovelaceConfigForm | undefined> {
return { schema: this.schema };
}
protected updated(changedProperties: PropertyValues): void {
super.updated(changedProperties);
if (changedProperties.has("schema") && this._configElement) {
// Propagate schema changes directly to the existing form editor element
// so dynamic changes (e.g. disabled flags based on selected entity) are
// reflected without needing to tear down and recreate the editor.
(this._configElement as HuiFormEditor).schema = this.schema;
}
}
}
declare global {