Skip to content
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

Support for Scope Elements #2957

Open
say25 opened this issue Jul 9, 2021 · 5 comments
Open

Support for Scope Elements #2957

say25 opened this issue Jul 9, 2021 · 5 comments
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. Has Workaround This PR or Issue has a work around detailed within it. Request For Comments Seeking commentary on an issue or PR from the community

Comments

@say25
Copy link

say25 commented Jul 9, 2021

Stencil version:

I'm submitting a:

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

Currently custom elements can conflict when multiple WebComponents have custom elements with the same name on the page.

Expected behavior:

Steps to reproduce:

  • Create a Stencil Component that has a custom element with the name hello-world-component that renders "Hello World"
  • Create another Stencil Component that has a custom element with the name hello-world-component that renders "Hello World 2"
  • Include both on the same page and see a conflict in behavior as only one can be registered.

Other information:

@ionitron-bot ionitron-bot bot added the triage label Jul 9, 2021
@johnjenkins
Copy link
Contributor

not saying this isn't valid, however if you need to do this now there are ways:

  1. with the dist bundle: import { defineCustomElements } from '@yourcomponent/libraryname/dist/loader'; ... defineCustomElements(window, { transformTagName: tagName => `unique-prefix-${tagName}` })
  2. with with dist-custom-elements bundle, after importing and when defining you can use https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define

The gotcha with these methods is that stencil doesn't replace tag names within a components' internal jsx. For that you can do something like:

const InnerComponent = `inner-component${suffix}`;
return (
    <Host>
        <InnerComponent />
    </Host>
)```

@splitinfinities splitinfinities added Feature: Compiler Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. Request For Comments Seeking commentary on an issue or PR from the community labels Aug 17, 2021
@ionitron-bot ionitron-bot bot removed the triage label Aug 17, 2021
@splitinfinities splitinfinities added the Has Workaround This PR or Issue has a work around detailed within it. label Aug 17, 2021
@splitinfinities
Copy link
Contributor

Hey there, thank you for the patience getting back to you! This idea is interesting for sure. If there are alternatives, please share the. If you want to see something like this in the Stencil code please 👍 !

@mayerraphael
Copy link

Wanted to bump this. Since October 2023 the first browser tests are getting green:

https://wpt.fyi/results/custom-elements/scoped-registry?label=experimental&label=master&aligned

@raveenita
Copy link

Hi @splitinfinities
Can we work in this via open source?
Our project have this necessities and workarounds in my opinion doen'st worth it if we can make a difference

@christian-bromann
Copy link
Member

@raveenita yes, we would love any contributions to this. I am happy to support when any technical question arise. Mind providing some insights in how you would like to implement this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Want this? Upvote it! This PR or Issue may be a great consideration for a future idea. Has Workaround This PR or Issue has a work around detailed within it. Request For Comments Seeking commentary on an issue or PR from the community
Projects
None yet
Development

No branches or pull requests

7 participants