ProjectEvergreen / ProjectEvergreen/wcc

optimize how initial HTML is set on initial render for JSX usage (Shadow DOM detection)

Open
#138 2 comments 0 reactions 1 assignee View on GitHub

@KaiPrince is already working on this.

Since Mar 19, 2026.

enhancement good first issue JSX
Dominant language
JavaScript
Stars
126
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Summary

Currently as part of initializing a component (either Light or Shadow DOM) from render function when using JSX, we use innerHTML in a couple scenarios

  1. Light DOM uses innerHTML
  2. Shadow DOM, if there is a root but no HTML (like say injecting dynamic content at run time, a la htmx)
const renderHandler = hasShadowRoot
  ? `
      const template = document.createElement('template');
      template.innerHTML = \`${serializedHtml}\`;

      if(!${elementRoot}) {
        this.attachShadow({ mode: 'open' });
        this.shadowRoot.appendChild(template.content.cloneNode(true));
      } else {
        this.shadowRoot.innerHTML = template.innerHTML;
      }
    `
  : `${elementRoot}.innerHTML = \`${serializedHtml}\`;`;

Details

It would be nice in either of these cases if we could just "push" the template right into the node, instead of using innerHTML which has a couple downsides

  • In some cases it just wont work - #130
  • even if it did, it invokes the HTML parser, which is an overhead
  • potential security concern around XSS

So, instead would be nice to see if we could leverage actual DOM APIs , like say replaceWith, just like we are able to leverage appendNode.

const renderHandler = hasShadowRoot
  ? `
      const template = document.createElement('template');
      template.innerHTML = \`${serializedHtml}\`;

      if(!${elementRoot}) {
        this.attachShadow({ mode: 'open' });
        this.shadowRoot.appendChild(template.content.cloneNode(true));
      } else {
        this.shadowRoot.replaceNode(template);
      }
    `
  : `${elementRoot}.innerHTML = \`${serializedHtml}\`;`;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.