Skip to content

Replace deprecated method getInnerHTML with getHTML #177

@DannyMoerkerke

Description

@DannyMoerkerke

Type of Change

Alignment with specs

Summary

Replace the deprecated Element.prototype.getInnerHTML with Element.prototype.getHTML in dom-shim.js

Details

This issue is in addition to my PR #171

Element.prototype.getInnerHTML has been deprecated in favor of Element.prototype.getHTML (https://developer.mozilla.org/en-US/docs/Web/API/Element/getHTML).

Currently in dom-shim.js, the setter for innerHTML for the HTMLTemplateElement automatically and incorrectly adds a <template> tag with a shadowrootmode attribute to the HTML content of the HTMLTemplateElement itself.

The result is that the innerHTML property of the HTMLTemplateElement will return its HTML contents including the <template> tag which is incorrect and not according to the specs as it should only return its contents without this <template> tag.

Element.prototype.getInnerHTML should be replaced with Element.prototype.getHTML which provides an options argument that enables the serialization of child nodes that are shadow roots:

<section>
  <template shadowrootmode="open" shadowrootserializable>
    <p>foo</p>
  </template>
  <p>bar</p>
</section>

section.getHTML();

// returns:
<p>bar</p>

section.getHTML({{serializableShadowRoots: true});

// returns:
<template shadowrootmode="open" shadowrootserializable>
   <p>foo</p>
</template>
<p>bar</p>

This also makes sure that Custom Elements that have their shadow roots set through innerHTML can be server-side rendered:

const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.innerHTML = `...`;

Metadata

Metadata

Labels

0.16.0breakingdocumentationImprovements or additions to the website and / or documentationenhancementImprovement to existing functionality

Type

No type

Projects

Status

✅ Done

Relationships

None yet

Development

No branches or pull requests

Issue actions