mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-15 05:16:34 +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}.`,
|
||||
config
|
||||
);
|
||||
// Custom elements are required to have a - in the name
|
||||
if (!tag.includes("-")) {
|
||||
return element;
|
||||
}
|
||||
element.style.display = "None";
|
||||
const timer = window.setTimeout(() => {
|
||||
element.style.display = "";
|
||||
@ -244,20 +248,26 @@ export const getLovelaceElementClass = async <
|
||||
|
||||
if (customTag) {
|
||||
const customCls = customElements.get(customTag);
|
||||
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
|
||||
);
|
||||
if (customCls) {
|
||||
return customCls;
|
||||
}
|
||||
|
||||
customElements
|
||||
.whenDefined(customTag)
|
||||
.then(() => resolve(customElements.get(customTag)));
|
||||
})
|
||||
);
|
||||
// Custom elements are required to have a - in the name
|
||||
if (!customTag.includes("-")) {
|
||||
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}`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user