question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[scoped-elements] align API more with CustomElementsRegistry proposal

See original GitHub issue

As the use of the scoped-elements experiment is in full force in Lion (https://github.com/ing-bank/lion/pull/599), we see some developer questions/discussions about the use of classnames instead of tagnames. We also see that the CustomElementsRegistry proposal is getting an official explainer by Justin. (https://github.com/w3c/webcomponents/pull/865)

Here, I’d like to propose some changes to scoped-elements in order to align more to the “current” target.

  • only allow scoped elements within shadow roots
  • abstract away the use of the versioned tagnames by:
    • polyfilling the most used API’s: shadowRoot.querySelector, shadowRoot.querySelectorAll, styles (this could use the same algorithm as the template transformation)
    • adding support for the proposed shadowRoot.createElement(), shadowRoot.createElementNS(), shadowRoot.importNode()

The benefits I see from this:

  • the use of tag name within code would be still allowed (no big refactors for users)
  • migration to the new CustomElementsRegistry will be possible by only updating ScopedElementsMixin (when creating the shadowRoot, you’ll be able to pass the a CustomElementsRegistry object with the element’s scopedElements `)
  • there might be some possibility to hide the usage of the ScopedElementsMixin in a build step (by analyzing the imports and rewriting them and creating a scopedElements property) Gut feeling says it might be error prone, though.

Let me know what you think: @manolakis, @LarsDenBakker, @daKmoR , @jorenbroekema

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
LarsDenBakkercommented, Feb 28, 2020

Until scoped custom element registry becomes a web standard, I don’t think we should be going anywhere near anything resembling a polyfill. We’ve had too many bad experiences with that in the web component ecosystem. So overwriting built-in functions is definitely something I think we shouldn’t do.

The goal for scoped elements is to solve only the problem of using multiple versions of a web component on a page, in the lightest way possible with the most minimal impact on DX and performance. (it’s quite a DX improvement actually in my opinion).

Of course if we can align as much as possible to how it might eventually look like, that would be ideal. That way the transition will be easier. It’s also important that whatever we do, multiple implementations can coexist on the page. This way a migration away from scoped element doesn’t need to be a big bang.

I’m also hoping that if we get native support for scoped custom element registries, we would be able to use this under the hood in the scoped elements library. By keeping the library simple and focused, this should be possible.

Finally I think we should be clear in our documentation that the scoped elements project is not suitable for every kind of application, it should only be used when using multiple versions is a dealbreak for your project.

0reactions
stale[bot]commented, Apr 23, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Open Web Components!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scoped Custom Element Registries - WICG/webcomponents
This proposal allows for multiple custom element definitions for a single tag name to exist within a page. This is accomplished by allowing...
Read more >
scoped-registries - npm Package Health Analysis | Snyk
Learn more about scoped-registries: package health score, popularity, security, ... Scoped Elements - Proposal to align the API with CustomElementsRegistry ...
Read more >
Development: Scoped Elements - Open Web Components
Scoped Custom Element Registries is a proposal that will solve this problem, but until it is ready, or a polyfill becomes available, we...
Read more >
Principles: Scoped Elements - Lion
This causes bottlenecks in software delivery that should be managed by the teams and complex build systems. Scoped Custom Element Registries is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found