- From: Ryosuke Niwa <notifications@github.com>
- Date: Mon, 14 Sep 2020 16:15:45 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/871/692367364@github.com>
> > > 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. I'm pretty sure this isn't a common use case but it's still not a good idea to violate the previously agreed contract that `attachShadow` returns a `ShadowRoot` that's otherwise inaccessible. > > 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? Yeah, allowing it based on custom element state would be okay as well. The issue is really about someone calling `attachShadow` prior to custom element being upgraded. -- 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-692367364
Received on Monday, 14 September 2020 23:15:57 UTC