From a3b714e8ea608b007aa414171c5fbc90f4fcf998 Mon Sep 17 00:00:00 2001 From: Sasha Firsov Date: Sat, 4 May 2024 10:35:58 -0700 Subject: [PATCH] sync tags registry fix --- src/custom-element.js | 16 ++++++++++------ src/http-request.js | 9 ++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/custom-element.js b/src/custom-element.js index ac691b9..ab38202 100644 --- a/src/custom-element.js +++ b/src/custom-element.js @@ -166,8 +166,8 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' ) - - + + @@ -206,8 +206,7 @@ createXsltFromDom( templateNode, S = 'xsl:stylesheet' ) {//attr} {def} - - + @@ -693,12 +692,17 @@ CustomElement extends HTMLElement get dce(){ return dce } } + const registerTag = tag => + { + if( window.customElements.get(tag) !== DceElement ) + window.customElements.define( tag, DceElement); + }; if(tag) - window.customElements.define( tag, DceElement); + registerTag(tag); else { const t = tagName; this.setAttribute('tag', t ); - window.customElements.define( t, DceElement); + registerTag(t); const el = document.createElement(t); this.getAttributeNames().forEach(a=>el.setAttribute(a,this.getAttribute(a))); el.append(...[...this.childNodes].filter( e => e.localName!=='style') ); diff --git a/src/http-request.js b/src/http-request.js index 53715e5..c406922 100644 --- a/src/http-request.js +++ b/src/http-request.js @@ -33,7 +33,7 @@ export class HttpRequestElement extends HTMLElement async fetch() { - if( !this.closest('custom-element') ) + if( !this.closest('body') ) return; const url = attr(this, 'url') || ''; if( !url ) @@ -61,8 +61,11 @@ export class HttpRequestElement extends HTMLElement slice.response = r; update(); - slice.data = await response.json(); - update(); + if( r.headers['content-type']?.includes('json')) + try + { slice.data = await response.json(); + update(); + }catch(_e){} } attributeChangedCallback(name, oldValue, newValue)