Skip to content

Support getInnerHtml() for SSR of declarative shadow DOM #210

@ttraenkler

Description

@ttraenkler

linkedom would be a great fit for lightweight SSR of web components, missing only Element.getInnerHTML(). Here is a polyfill that might serve as a starting point for an implementation.

For server side rendering of web components, declarative shadow DOM has recently been standardized and shipped in all major browsers except Firefox, Mozilla's position being positive on this feature as well.

Similar to Element.innerHTML, the new function Element.getInnerHTML() will serialize DOM elements including the shadowroots of custom elements which are skipped by innerHTML. In essence, wherever a <custom-element> is found in the DOM, the corresponding template will be inlined with <template shadowrootmode="open"> (note this was recently renamed from shadowroot="open" which the above mentioned polyfill still uses).

Instead of

element.innerHTML

producing

   <custom-element>
      <h2>light content</h2>
    </custom-element>

the new function

element.getInnerHTML({includeShadowRoots: true})

will include the shadowroot

   <custom-element>
      <template shadowrootmode="open">
        <p id="a">shadow a</p>
        <p id="b">shadow b</p>
        <p id="c">shadow c</p>
        <slot></slot>
      </template>
      <h2>light content</h2>
    </custom-element>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions