Re: [WICG/webcomponents] Scoped Custom Element Registries (#716)

> Soo, this has been open for a while. Does anyone have a polyfill for any of the suggestions?

we are currently using this
https://github.com/webcomponents/polyfills/tree/master/packages/scoped-custom-element-registry

> Can we push this or any unregister-way so that native web components would be able to gain HMR capabilities?

you might wanna take a look at
https://open-wc.org/docs/development/hot-module-replacement/

> Right now, what I can see is that if we hijack the current registry, we could define elements with a hash in them, make a shim for the original name that then pass everything to the hashed version and just continuously re-register with a new hash and re-render.

you mean register not the "actual" component name but `my-component-2dfjk43`? 
this is how version of scoped elements was implemented
https://www.npmjs.com/package/@open-wc/scoped-elements/v/1.3.3

it sort of works... but 
- it's not fully scoped (can be misused and you still have access to the global registry which can result in issues if you move nodes from light to shadow dom or vise versa)
- css selectors do not work
- annoying to use in tests (as tag names are always different)

in version 2 we are now using the scoped custom elements registry linked above

---- 

@trusktr 
> This is a really good point. Suppose we took this problem to JavaScript. Imagine we have this code:
> ```js
> let foo = 123
>
> function doIt() {
>   console.log(foo)
> }
> ```

IMHO this is taking the wrong "conclusion". Writing code like this couples your function into a specific location in the code. e.g. you will not be able to move your `doIt` function into any other file... which is probably fine for JS but we don't wanna have web component that only work if rendered in a specific dom.

e.g. if I define my custom element and it uses a `<sub-el>` in its shadow dom... it needs to bring that `sub-el` with it.. don't expect other web components to be available globally

```html
<my-el>
  # shadow-dom
      <sub-el></sub-el>
</my-el>      
```

We have been using ScopeElements for ~2 years now and explicitly defining ALL web component you use in your shadow dom is absolutely essential. And yes you can still say to grab a specific component from the global registry... but you need to be aware that this component becomes "less shareable".

We specifically added an example for that

https://open-wc.org/docs/development/scoped-elements/#usage

![Screenshot 2022-02-08 at 12 32 08](https://user-images.githubusercontent.com/24378/152978919-220eb1a3-dd68-4095-a8fc-9aec01183bca.png)





-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/716#issuecomment-1032511860
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/716/1032511860@github.com>

Received on Tuesday, 8 February 2022 11:36:21 UTC