ProjectEvergreen / greenwood

Greenwood is your full-stack workbench for the web, focused on supporting modern web standards and development to help you create your next project.
https://www.greenwoodjs.io
MIT License
94 stars 9 forks source link

support `prerender` during development #1249

Open thescientist13 opened 2 weeks ago

thescientist13 commented 2 weeks ago

Summary

While Greenwood supports prerendering pages at build time, for example, having a "client" side component like this

<! -- src/pages/index.html -->
<html>
  <head>
    <script type="module" src="./components/header.js"></script>
  </head>
  <body>
    <app-header></app-header>
</html>

This actually doesn't take place during development, so it is very common to see layout shifts and FOUC, as well as not having the same behavior during development and production! 🫨

Details

The main trick is what to do about the <script> tag in the head, because if you have a Light DOM component, e.g.

// src/components/header.js
export default class Header extends HTMLElement {
  connectedCallback() {
    this.innerHTML = '<h1>Welcome to my website!</h1>'
  }
}

customElements.define('x-header', Header);

if you don't "guard" it like you would with declarative shadow DOM, e.g.

```js export default class Header extends HTMLElement { connectedCallback() { if(this.innerHTML) return; this.innerHTML = '

Welcome to my website!

' } } customElements.define('x-header', Header); ``` You'll see duplicate rendering. // TODO get a screenshot! @thescientist13 So maybe could we strip the ` Githubissues.
  • Githubissues is a development platform for aggregating issues.