Guard passing invalid tag to customElements.whenDefined (#7696)

This commit is contained in:
Paulus Schoutsen 2020-11-17 09:40:35 +01:00 committed by GitHub
parent bf7424a67c
commit 7d3acc747d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,9 +248,16 @@ export const getLovelaceElementClass = async <
if (customTag) {
const customCls = customElements.get(customTag);
return (
customCls ||
new Promise((resolve, reject) => {
if (customCls) {
return customCls;
}
// 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}`)),
@ -256,8 +267,7 @@ export const getLovelaceElementClass = async <
customElements
.whenDefined(customTag)
.then(() => resolve(customElements.get(customTag)));
})
);
});
}
const tag = `hui-${type}-${tagSuffix}`;