Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX components not rendering into a declarative shadow root (e.g. <template> tag) #128

Closed
thescientist13 opened this issue Jan 2, 2024 · 0 comments · Fixed by #129
Closed
Assignees
Labels
0.11.0 bug Something isn't working documentation Improvements or additions to documentation
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jan 2, 2024

Summary

Noticed that if trying to do something like this

export default class HeadingComponent extends HTMLElement {
  sayHello() {
    alert(`hello world!`);
  }

  connectedCallback() {
    if (!this.shadowRoot) {
      this.attachShadow({ mode: 'open' });
      this.render();
    }
  }

  render() {
    return (
      <button onclick={this.sayHello}>Get a greeting!</button>
    )
  }
}

customElements.define('wcc-heading', HeadingComponent);

The output I was getting was not including a wrapping <template> tag.

{
  html: '\n' +
    '        <wcc-heading>\n' +
    '          <button onclick="this.getRootNode().host.sayHello()">Get a greeting!</button>\n' +
    '        </wcc-heading>\n' +
    '      '
}

Details

One thing to call out is that normally the initial HTML is setup from some direct call to innerHTML, e.g.

export default class Header extends HTMLElement {
  connectedCallback(){
    this.innerHTML = 'Hello World!';
  }
}

But now with a render function handling all that, will still need that signal, which looks to be in the code, but should probably call this out more explicitly in the JSX section of the docs, since you would be using render instead of shadowRoot.innerHTML now.


Also looks like there was never a test made for this so that probably explains why its not working 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.11.0 bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant