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

> > 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.

Is this a common/recommended use case? A script that attaches a shadow root to a non-upgraded custom element, and a custom element that then has no control of its own shadow content? This seems problematic anyway - my guess would be that a normal custom element definition would already be throwing exceptions on `attachShadow()`. Perhaps I'm missing the use case here.

> 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.

I'm generally ok with the idea of setting a flag, but I think it would be an ergonomic problem if CE authors had to always remember to call `attachInternals()` prior to calling `attachShadow()`, or the shadow root wouldn't be available. Maybe this isn't a huge deal, but it does seem "odd". Perhaps instead, the flag gets set if `attachShadow()` is called while the custom element is in the "precustomized" or "customized" state? (Or by a declarative shadow root.) This would get you what you want, I think, in that calls to `attachShadow()` prior to the constructor will not be exposed to ElementInternals, but without the strict ordering of calls to `attachInternals()` and `attachShadow()` **within** the constructor. WDYT?

-- 
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-692341099

Received on Monday, 14 September 2020 22:12:36 UTC