From d185473adee698da917585e14ba5eb2d550737b3 Mon Sep 17 00:00:00 2001 From: Sebbe Selvig Date: Wed, 28 Dec 2022 12:37:55 +0100 Subject: [PATCH] Add empty string check and use wrapping tag as default --- lib/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index b40b7dc..d664d8e 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -114,19 +114,19 @@ export function mount( document.getElementsByTagName('body')[0].prepend(el) } return injectStylesBeforeElement(styleOptions, document, el).then(() => { - // by default we mount the component into the created element + // by default, we mount the component into the created element let target = el - if (styleOptions && styleOptions.html) { - el.innerHTML = styleOptions.html - target = document.getElementById('here') - if (!target) { - console.error('mount has HTML with DIV with ID "here"') - console.error(styleOptions.html) - throw new Error( - 'Could not find element with ID "here" in the HTML passed', - ) - } + const wrapperHtml = styleOptions && typeof styleOptions.html === 'string' && styleOptions.html.trim() !== '' ? styleOptions.html : '
'; + + el.innerHTML = wrapperHtml; + target = document.getElementById('here') + if (!target) { + console.error('mount has HTML with DIV with ID "here"') + console.error(styleOptions.html) + throw new Error( + 'Could not find element with ID "here" in the HTML passed', + ) } const allOptions = Object.assign({}, options, {