Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

partial hydration (side effect free custom elements, e.g. tree shaking) #11

Closed
thescientist13 opened this issue May 1, 2022 · 0 comments
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented May 1, 2022

Type of Change

  • New Feature Request

Summary

To build off of #3 , the next level of granularity to try and achieve in hydration strategies is partial hydration, which is

Use knowledge of the client vs server to only ship code / serialize data needed in the browser.

Details

Which I basically interpret to mean that given a component like this

class Header extends HTMLElement {
  constructor() {
    super();

    if (this.shadowRoot) {
      const button = this.shadowRoot.querySelector('button');

      button.addEventListener('click', this.toggle);
    }
  }

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

  toggle() {
    alert('this.toggle clicked!');
  }

  render() {
    return `
      <style>
        .header {
          background-color: #192a27;
          min-height: 30px;
          padding: 10px;
          font-size: 1.2rem;
        }

        ...
      </style>

      <header class="header">
        ...
      </header>
    `;
  }
}

export { Header };
customElements.define('wcc-header', Header);

Since there are no props or state, we should be able to infer

  • Only one render is needed, which can be handled via declarative shadow dom
  • We still need the event handler

So in an ideal world, this is what would actually be shipped to the browser

class Header extends HTMLElement {
  constructor() {
    super();

    if (this.shadowRoot) {
      const button = this.shadowRoot.querySelector('button');

      button.addEventListener('click', this.toggle);
    }
  }

  toggle() {
    alert('this.toggle clicked!');
  }
}

export { Header };
customElements.define('wcc-header', Header);
@thescientist13 thescientist13 added the feature New feature or request label May 1, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone May 1, 2022
@thescientist13 thescientist13 added expirement feature New feature or request and removed feature New feature or request labels May 27, 2022
@ProjectEvergreen ProjectEvergreen locked and limited conversation to collaborators Oct 2, 2024
@thescientist13 thescientist13 converted this issue into discussion #169 Oct 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant