WICG / webcomponents

Web Components specifications
Other
4.36k stars 370 forks source link

[scoped-registries] Should WC be usable as "views"? #998

Closed chalbert closed 1 year ago

chalbert commented 1 year ago

Web Components have been up to now mostly used as low-level, presentational components. Inside a modern app, there are other type of components that I usually categorise under "views". Common view type may include micro-apps, sections, tabs, modals, etc. (not talking about the actual tab and modal UI component, but reusable tabs and modals with large business flow inside)

App
   MicroApp1
       Section1 
          Tab1
          Tab2
       Section2
          Modal1
   MicroApp2
      Section2
          Modal1
      Section3
          Tab1
          Tab3

I would like to get the community's opinions on possible use of WC as views.

  1. Should we aim at making it possible for WC to be used as views?
  2. Should those views use lightDOM?

My own answers are:

  1. Yes
  2. Yes
sashafirsov commented 1 year ago

It is rather a question than proposal. The answer is simple: it is already possible and widely used.

Any Web Component can be as container as just a self-sufficient UI. The "view" you are talking is a container. Either shadow DOM or light DOM can be used for container.

Here are the samples of the SLOT based containers with light DOM: @epa-wg/custom-element, slotted-element, light-dom-element.

Most of web components are working with SLOT as container via shadow DOM. That is just one of samples: shadow-dom-element

The discussions of using the template-based Web Components without shadow DOM are in progress. Here is just one of those: Functionally complete declarative templating.

It is unclear why this topic is marked by scoped-registries. Please elaborate the relation.

sashafirsov commented 1 year ago

The ability to embed microapplications into another Declarative Web Application and Declarative Custom Element is covered by DWA manifest, there are row of proposals related to the concept are in baking and under review.

Of course the embedding is not limited to the Declarative ones, the usual Web Components can be injected as well but it would be unsecure as JS is not limited by scope insulation layer. That is addressed by embed-page microapplication container POC. There is no proposal ready on that level yet. LMN if wanted to chime in.

chalbert commented 1 year ago

Thanks @sashafirsov , I'll have a read on the links you've referenced, it sounds very interesting.

As for the relation to scoped-registries, if the use case is valid as you've hinted, then I would suggest that view-type components would benefit greatly from scoped registries and it should be considered at part of its design.

I was starting by gauging opinion on the subject, as if view-type components are out of scope by consensus, there is not much point going forward with a proposal.