-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shadow DOM mode as opt-in feature flags #1049
Comments
@rniwa Here is the new issue as requested. Would you like a new issue per feature flag, or is it enough to discuss the broader idea here before getting that segmented? I realize each of these flags could generate a lot of questions that may need to be discussed in detail in separate threads, but I didn't want to create noise. |
Relaxing Shadow DOM encapsulation? I've had strong opinions both ways. But I have a new understanding now as I've eventually found that many of these pain points aren't even a Web Components'/ Shadow DOM's call. For example, should basic things like style scoping and ID/IDREF scoping really warrant a Shadow DOM? (Look how many years it has taken to realise the answer to the first- in the return of scoped CSS, i.e. What I see is clear appetite to have most of these features outside of the Shadow DOM, i.e. in the open HTML/DOM land. And my new belief is that the Shadow DOM might be just already great for the right use cases, assuming we find outside answers to the more common non-shadow scenarios, as we're now doing with scope styles. Put another way, haviing the Shadow DOM as the one means to those ends is what I see as the problem. |
Possible related discussions;
While the first is centered on styling, the second is kind of a bigger picture proposal apanning style and script scoping, ID and IDREFS namespacing, etc. |
Thank you
I think we can start with this umbrella issue. What does not having |
@ox-harris I agree with you that having Shadow DOM as the only option for many of the features it provides is an issue. I'm very happy to see the return of |
@rniwa Here's how I see those working and being helpful. Omitting
|
Few comments:
|
@gregwhitworth may be interested in this one. I've heard from him that Salesforce has issues with certain encapsulations that cause incompatibilities with legacy scripts. For instance, some jQuery-style widget may get it's container element by doing a query selector for a user provided id. Opting out of |
One thing about this issue is that I don't think the attribute and syntax matter much right now compared to whether it's possible to decouple types of encapsulation in the first place, and what the exact semantics are - ie, if you could opt out of selector encapsulation, would that open the shadow root to queries from scopes above it, or from the document? |
Hi, @caridy. Thank you for your questions and the opportunity to be more clear in my proposal. First and foremost, none of what I am proposing is new functionality; it's a means of selectively opting into various subsets of existing functionality that you currently have to use either all together or not at all. I think it will be easiest to answer your questions in reverse order. 5. Because each flag is opt-in, overlap doesn't matter. For example setting mode to 4. Because each flag is opt-in, specifying 3. Even with 2. The effect of 1. The benefit of using whitespace-delimited values is that it allows you to set multiple values when using declarative Shadow DOM: |
@justinfagnani is spot on. honestly, for some of the encapsulation described above (e.g.: styles), I don't think decoupling is possible, at least without a significant amount of work for perhaps some of the encapsulation. For others, (e.g.: ids, and lightdom slots) they just don't make sense, my brain chokes when thinking about that. Let's figure out what's possible, and then work on the ergonomics. |
First, thank you @shannonmoeller for filing the issue +1 to @justinfagnani and @caridy points on the issues discussed to @shannonmoeller proposal My overall opinion on this has changed over the years and I agree with this statement by @ox-harris
I would actually recommend the inverse of this and say we should try and figure out how to bring custom elements with I've raised this in the past so I know there is a can of worms for supporting In either scenario though, I am curious how a developer would know which capabilities they have when consuming someone else's component without resorting to Javascript which speaks to @caridy point of the potential matrix we have? This is important to consider if I'm using someone else's web component and all I want to do is cross reference an ID or style a child; how do I easily know that's possible? I digress. |
The Shadow DOM was originally built as an all-or-nothing API to encapsulate a broad range of functionality. Since then, there have been many recommendations around selective means of working around that encapsulation, including
mode: "open"
, the::part
and::slotted
CSS features, a newopen-styleable
mode, and userland requests for such things as Light DOM slots. At the core of each of these requests is the thought, "The Shadow DOM does too much; how can we make it do less?"What if, instead of debating how to allow people to opt out, we instead look at a way to make Shadow DOM features individually opt-in with feature flags? We could treat
mode
more akin to<iframe>
’ssandbox
attribute where multiple flags can be set (though even that API suffers from flags that opt out, instead of opting in).JavaScript example:
Declarative example:
I propose we change
mode
from being a single-value string to being a whitespace-delimited multi-value string with the following flags to start (the names could change and the list could be longer or shorter):encapsulate-ids
: Omitting this value is useful for allowing unique items on the page to exist in a declarative Shadow DOM to enable deep linking, id-referencing via aria attributes, id-referencingfor=""
attributes, etc. There is currently no alternative to this feature.encapsulate-events
: Omitting this value is useful for web components that consist of several related but unique form fields and buttons, such as checklists, address fieldsets, credit card fieldsets, etc., as well as component libraries that wrap buttons and inputs with specific styling, but otherwise wish the Shadow DOM children to behave regularly. This would be a simpler alternative to the Form Associated API.encapsulate-styles
: Omitting this value is useful for allowing Light DOM styles to apply to Shadow DOM children. This fulfills the intent of and could be an alternative solution to theopen-styleable
recommendation.delegates-focus
: Allows for setting thedelegatesFocus
option of.attachShadow()
declaratively which I don't believe is currently possible.private-accessor
: Prevents the definition of the.shadowRoot
property on the host element.open
: Would be redeclared as a preset of theencapsulate-ids
,encapsulate-events
, andencapsulate-styles
values.closed
: (default value ifmode
is omitted) Would be redeclared as a preset of theprivate-accessor
,encapsulate-ids
,encapsulate-events
, andencapsulate-styles
values.none
: A value that explicitly disables all other flags. This would solve the intent behind requests for "Light DOM, but with slots." I believe for slots to be effective a host of some kind is still needed. If users wish for slots throughout a page, this would be easy enough to implement by wrapping page contents in<template shadowrootmode="none">
.I don't believe we need a flag as a means of toggling slots as that appears to be an intrinsic feature of Shadow DOM and it's "toggled" by the existence or non-existence of
<slot>
elements within the Shadow DOM markup.Updating
mode
to be a list of feature flags could allow for solving the current needs for granular control of encapsulation while also opening the door for future additional Shadow DOM features without breaking backwards compatibility or declarative usage.Originally posted by @shannonmoeller in #909 (comment)
[Updated 2024-02-14]: Added the
private-accessor
flag to make that opt-in apart fromclosed
.The text was updated successfully, but these errors were encountered: