Re: [w3c/webcomponents] Expose shadowRoot on element internals (#871)

> > Can we split the change for `attachInternals` to its own PR instead of tying it to the change to expose `shadowRoot`?
> 
> Definitely - done. There are now two:
> 
> 1. [Prevent attachInternals() use before custom element constructor](https://github.com/whatwg/html/pull/5909)
> 2. [Add ElementInternals.shadowRoot](https://github.com/whatwg/html/pull/5912)

Thanks.

> > I also wonder if there is a way to restrict `attachShadow` until the constructor is called. Right now, when you call `attachInternals` and get the shadow root, you don't know whether it's coming from the declarative shadow root or some shadow root other scripts have attached. The combination of upgrading and backwards compatibility makes this challenging. Because of upgrades, we wouldn't know whether a given element will allow shadow root or not. If backwards compatibility weren't an issue, we could make `attachShadow` fail until the constructor is called.
> > One possibility is to automatically fail an upgrade when non-declarative shadow root had been attached before the constructor has been called when internals is enabled. ...
> 
> One alternative suggestion might just be to add a flag for declarative shadow roots, so that the constructor can tell the difference? E.g. `shadowRoot.isDeclarative` or something?

That would solve the issue that custom element author can tell whether a shadow root was attached by scripts or declarative shadow root but doesn't solve the issue that the existing scripts which call `attachShadow` is forced to disclose the shadow root to custom elements, which isn't great either.

Here's one more idea. `ElementInternals` can only expose `ShadowRoot` if it's created after `ElementInternals` itself, or a some flag is set, and declarative shadow root would set this flag by default.

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

Received on Monday, 14 September 2020 21:59:42 UTC