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

support server rendering a native HTMLElement #935

Closed
1 of 5 tasks
thescientist13 opened this issue May 29, 2022 · 0 comments · Fixed by #943 or #956
Closed
1 of 5 tasks

support server rendering a native HTMLElement #935

thescientist13 opened this issue May 29, 2022 · 0 comments · Fixed by #943 or #956
Assignees
Labels
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented May 29, 2022

Type of Change

  • New Feature Request
  • Documentation / Website
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

(grabbed some of this from #926 )

Would like Greenwood to come up with a native solution to HTMLElement SSR rendering, coming out my conversations in the Lit repo - lit/lit#2092 (comment)

The goal would be to leverage Declarative Shadow DOM and provide a default alternative to puppeteer, and moving puppeteer to a custom plugin instead, including all the @webcomponents polyfill dependencies. Effectively this is providing a Next.js like pages experience, but for native custom elements.

Details

I suppose there are two outcomes from this:

  1. Server rendering your client code (e.g. prerender + static)
  2. As part of wcc, we could potentially allow a custom element to be the export and Greenwood can use renderToString to get the final HTML.
    import './path/to/card.js';
    
    export default class ArtistsPage extends HTMLElement {
      async connectedCallback() {
        if (!this.shadowRoot) {
          const artists = await fetch('https://www.analogstudios.net/api/artists').then(resp => resp.json());
          const html = artists.map(artist => {
            return `
              <wc-card>
                <h2 slot="title">${artist.name}</h2>
                <img slot="image" src="${artist.imageUrl}" alt="${artist.name}"/>
              </wc-card>
            `;
          }).join('');
    
          this.attachShadow({ mode: 'open' });
          this.shadowRoot.innerHTML = html;
        }
      }
    }

Because of how wcc works, we should be able to get card.js back as metadata that we can feed into the bundler, which means there would be no need to specify it via <script> tags in the template, which means this could potentially usurp the need for getTemplate and getPage?

@thescientist13 thescientist13 added CLI SSR feature New feature or request labels May 29, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone May 29, 2022
@thescientist13 thescientist13 self-assigned this May 29, 2022
@thescientist13 thescientist13 pinned this issue May 29, 2022
@thescientist13 thescientist13 moved this from TODO to IN PROGRESS in 8 - SSR Enhancements May 29, 2022
@thescientist13 thescientist13 moved this from IN PROGRESS to IN REVIEW in 8 - SSR Enhancements Jun 23, 2022
@thescientist13 thescientist13 moved this from IN REVIEW to DONE in 8 - SSR Enhancements Jul 1, 2022
@thescientist13 thescientist13 linked a pull request Jul 1, 2022 that will close this issue
19 tasks
@thescientist13 thescientist13 mentioned this issue Jul 1, 2022
19 tasks
@thescientist13 thescientist13 unpinned this issue Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
1 participant