Re: [whatwg/dom] Declarative Shadow DOM (#831)

> If I'm making <distributable-widget>, I have no control over how it's going to be consumed — whether it's going to be in an app that uses a WC SSR framework, or if it's going to be used in a document without declarative shadow DOM, or if it's going to be created programmatically. So at the very least, the constructor is going to need to accommodate both the case where declarative shadow DOM exists, and the case where it doesn't:

@Rich-Harris With a natural extension to my suggestion above you could rely on templates coming from a specific url e.g.:

```html
<world-time
  timezone="GMT+12"
  shadowroot="https://unpkg.com/world-time/template.html#default"
  shadowrootdata='{ "hour": 10, "minute": 20, second: "30" }'
></world-time>
```

```js
// world-time/component.js

const TEMPLATE_URL = new URL(
  './template.html#default',
  import.meta.url,
).href;

class WorldTimeComponent extends HTMLElement {
  constructor() {
    super();
    if (this.shadowRoot) {
      if (this.shadowRoot.templateUrl !== TEMPLATE_URL) {
        // DESTROY and replace shadow root
      }
    } else {
      // Create the shadow root
    }

    // Begin hydration, etc
  }
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/831#issuecomment-586581710

Received on Saturday, 15 February 2020 11:40:26 UTC