mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 13:56:35 +00:00
Guard passing invalid tag to customElements.whenDefined (#7696)
This commit is contained in:
parent
bf7424a67c
commit
7d3acc747d
@ -104,6 +104,10 @@ const _customCreate = <T extends keyof CreateElementConfigTypes>(
|
|||||||
`Custom element doesn't exist: ${tag}.`,
|
`Custom element doesn't exist: ${tag}.`,
|
||||||
config
|
config
|
||||||
);
|
);
|
||||||
|
// Custom elements are required to have a - in the name
|
||||||
|
if (!tag.includes("-")) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
element.style.display = "None";
|
element.style.display = "None";
|
||||||
const timer = window.setTimeout(() => {
|
const timer = window.setTimeout(() => {
|
||||||
element.style.display = "";
|
element.style.display = "";
|
||||||
@ -244,20 +248,26 @@ export const getLovelaceElementClass = async <
|
|||||||
|
|
||||||
if (customTag) {
|
if (customTag) {
|
||||||
const customCls = customElements.get(customTag);
|
const customCls = customElements.get(customTag);
|
||||||
return (
|
if (customCls) {
|
||||||
customCls ||
|
return customCls;
|
||||||
new Promise((resolve, reject) => {
|
}
|
||||||
// We will give custom components up to TIMEOUT seconds to get defined
|
|
||||||
setTimeout(
|
|
||||||
() => reject(new Error(`Custom element not found: ${customTag}`)),
|
|
||||||
TIMEOUT
|
|
||||||
);
|
|
||||||
|
|
||||||
customElements
|
// Custom elements are required to have a - in the name
|
||||||
.whenDefined(customTag)
|
if (!customTag.includes("-")) {
|
||||||
.then(() => resolve(customElements.get(customTag)));
|
throw new Error(`Custom element not found: ${customTag}`);
|
||||||
})
|
}
|
||||||
);
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// We will give custom components up to TIMEOUT seconds to get defined
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error(`Custom element not found: ${customTag}`)),
|
||||||
|
TIMEOUT
|
||||||
|
);
|
||||||
|
|
||||||
|
customElements
|
||||||
|
.whenDefined(customTag)
|
||||||
|
.then(() => resolve(customElements.get(customTag)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tag = `hui-${type}-${tagSuffix}`;
|
const tag = `hui-${type}-${tagSuffix}`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user