-
Notifications
You must be signed in to change notification settings - Fork 98
Description
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.innerHTMLproducing
<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>