linkedom icon indicating copy to clipboard operation
linkedom copied to clipboard

HTMLTemplateElement toString does not include contents

Open saviski opened this issue 2 years ago • 1 comments

https://github.com/WebReflection/linkedom/blob/ec5ce8470c50fe2e9ea6e8b339e6ee4f23077c73/esm/html/template-element.js#L19

I see that this related issue is marked as closed https://github.com/WebReflection/linkedom/issues/21

But later modifications removed this functionality

I am using this hack locally to get the functionality I need

  const originaltoString = Object.getOwnPropertyDescriptor(Element.prototype, 'toString')!
  Object.defineProperties(HTMLTemplateElement.prototype, {
    toString: {
      value() {
        return (
          originaltoString.value
            .call(this)
            .replace(/<\/template>$/, this.content.childNodes.join('')) + '</template>'
        )
      },
    },
  })

saviski avatar Jul 26 '23 13:07 saviski

the test works though ... I am not sure when/where/how you are having issues ... can you share a minimal broken example code instead of your fix? thanks!

WebReflection avatar Aug 28 '23 08:08 WebReflection