linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

not working HTMLTemplateElement Content append after innerHTML result empty string

Open visualkhh opened this issue 4 months ago • 2 comments

PR: https://github.com/WebReflection/linkedom/pull/315

const data: DocumentFragment = ...
const template = window.document.createElement('template') as HTMLTemplateElement;
template.content.append(data);

 console.log('innerHTML:', template.innerHTML, 'children:',Array.from(template.content.children));  // innerHTML emptyString

not working..

innerHTML output is empty string

 console.log('innerHTML:', template.innerHTML, 'children:',Array.from(template.content.children));

--log result-- innerHTML: children: [ <ref *1> HTMLStyleElement { ownerDocument: HTMLDocument { ownerDocument: null, localName: '#document', nodeType: 9, parentNode: null, [Symbol(next)]: [DocumentType], [Symbol(prev)]: null, [Symbol(private)]: null, [Symbol(end)]: [Object], [Symbol(CustomElements)]: [Object], [Symbol(MutationObserver)]: [Object], [Symbol(mime)]: [Object], [Symbol(doctype)]: [DocumentType], [Symbol(DOMParser)]: [class DOMParser], [Symbol(globals)]: null, [Symbol(image)]: null, [Symbol(upgrade)]: null, [Symbol(EventTarget)]: [DOMEventTarget] }, localName: 'style', nodeType: 1, parentNode: DocumentFragment { ownerDocument: [HTMLDocument], localName: '#document-fragment', nodeType: 11, parentNode: null, [Symbol(next)]: [Circular *1], [Symbol(prev)]: null, [Symbol(private)]: [HTMLTemplateElement], [Symbol(end)]: [Object] }, [Symbol(next)]: Attr { ownerDocument: [HTMLDocument], localName: 'id', nodeType: 2, parentNode: null, ownerElement: [Circular *1], name: 'id', [Symbol(next)]: [Attr], [Symbol(prev)]: [Circular *1], [Symbol(value)]: 'KQykvzSaQPUDomNDyYpuZNdcxkWCkvHtGvVujfjH-style', [Symbol(changed)]: false }, [Symbol(prev)]: DocumentFragment { ownerDocument: [HTMLDocument], localName: '#document-fragment', nodeType: 11, parentNode: null, [Symbol(next)]: [Circular *1], [Symbol(prev)]: null, [Symbol(private)]: [HTMLTemplateElement], [Symbol(end)]: [Object] }, [Symbol(private)]: null, [Symbol(end)]: { nodeType: -1, ownerDocument: [HTMLDocument], parentNode: null, [Symbol(next)]: [HTMLElement], [Symbol(prev)]: [Attr], [Symbol(start)]: [Circular *1] }, ... ]

I was thus treated with innerHTML.

  • template.innerHTM; .. template.content

But I think it needs to be fixed

visualkhh avatar Oct 06 '25 14:10 visualkhh

so template.innerHTML is empty but childrens are in there? I don't understand much around this issue, sorry ... please provide examples and expectations in a readable format, thanks!

WebReflection avatar Oct 06 '25 15:10 WebReflection

@WebReflection https://github.com/WebReflection/linkedom/pull/315 Please check the PR.

After appending the child element to the HTML Template Element's content If you do innerHTML, it is normal to output the contents of the child element, but it is not output in linkedom.

visualkhh avatar Oct 06 '25 15:10 visualkhh