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}.`, `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,9 +248,16 @@ 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) => { }
// 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 // We will give custom components up to TIMEOUT seconds to get defined
setTimeout( setTimeout(
() => reject(new Error(`Custom element not found: ${customTag}`)), () => reject(new Error(`Custom element not found: ${customTag}`)),
@ -256,8 +267,7 @@ export const getLovelaceElementClass = async <
customElements customElements
.whenDefined(customTag) .whenDefined(customTag)
.then(() => resolve(customElements.get(customTag))); .then(() => resolve(customElements.get(customTag)));
}) });
);
} }
const tag = `hui-${type}-${tagSuffix}`; const tag = `hui-${type}-${tagSuffix}`;