Repository navigation
Closed
Labels
Feature: Want this? Upvote it!This PR or Issue may be a great consideration for a future idea.Has WorkaroundThis PR or Issue has a work around detailed within it.Request For CommentsSeeking commentary on an issue or PR from the community
Description
Stencil version:
@stencil/[email protected]
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:
- Support for something like Scoped Elements
Steps to reproduce:
- Create a Stencil Component that has a custom element with the name
hello-world-componentthat renders "Hello World" - Create another Stencil Component that has a custom element with the name
hello-world-componentthat renders "Hello World 2" - Include both on the same page and see a conflict in behavior as only one can be registered.
Other information:
- An attempt to fix this with a prefix pattern was tried in feat(compiler) - Component Namespacing #843
- This was brought back up in feat(cli): Add ability to specify component generation config parameters #2427
Reacted by jase, Steven Yeh, jagadeeshaby, Mustafa Sak, Timo Schulz, Arvindan T A, Kulkarni Shravan Kashyap, Giamir Buoncristiani, Kylie Sy, Jon Hieb and 15 more
Metadata
Metadata
Assignees
Labels
Feature: Want this? Upvote it!This PR or Issue may be a great consideration for a future idea.Has WorkaroundThis PR or Issue has a work around detailed within it.Request For CommentsSeeking commentary on an issue or PR from the community
Activity
johnjenkins commentedon Jul 9, 2021
not saying this isn't valid, however if you need to do this now there are ways:
distbundle:import { defineCustomElements } from '@yourcomponent/libraryname/dist/loader'; ... defineCustomElements(window, { transformTagName: tagName => `unique-prefix-${tagName}` })dist-custom-elementsbundle, after importing and when defining you can use https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/defineThe gotcha with these methods is that stencil doesn't replace tag names within a components' internal jsx. For that you can do something like:
splitinfinities commentedon Aug 17, 2021
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 commentedon Feb 27, 2024
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 commentedon May 29, 2024
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 commentedon Nov 19, 2024
@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?
fcano-ut commentedon Jan 10, 2025
I was thinking what it would take for Stencyl to be compatible with scoped custom elements polyfill
When calling the
attachShadowfunction, we should pass aregistryoption that might be passed down to that function like this:I believe it would be as simple as that, but I might be totally wrong. I'm missing in the code the part where we avoid calling
defineCustomElementagain if the element is already called. If such a code exists, it should also need to be changed somehow 🤔 There's also code related to supporting Shadow DOM polyfills, but the custom element registry polyfill is not supporting those polyfills. So these two features might not work together, so that's something else that might cause complexity 🤔Anyway, that was just a little "what if" experiment. From what I can see, the Scoped Custom Element feature is still a WIP proposal, so I understand if Stencyl doesn't want to support that yet. We discussed forking Stencyl (or using
patch-packagesto override parts of the code), but we decided to wait a while and see if the proposal can move forward soon... Hope it does! 🤞johnjenkins commentedon Jan 10, 2025
@fcano-ut it depends on the output being generated...
For the
dist/ lazy loader output the proxy components (the skeleton elements that wait forconnectedCallbackbefore fetching / wiring in the 'real' class) define themselves hereFor the
custom-elementoutput the functions are created (via AST) so they can be bundled with each component module in-turn heresdvg commentedon Mar 25, 2025
I spent some time creating a POC using Scoped Custom Elements in a micro-frontend scenario.
Unfortunately, I ran into two major issues that make Scoped Elements impractical for our use case:
When a React app renders inside a Shadow Root with scoped
customElements, the custom element tags don’t upgrade to their corresponding Web Components. I assume this is because React usesdocument.createElementrather than the scoped version (shadowRoot.createElement) to instantiate elements. Other frameworks and libraries likely have the same limitation.Scoped Custom Elements require micro-frontends to be rendered inside a Shadow Root (as expected), but there’s no straightforward way to inherit global document styles within the Shadow Root. While this might not be a complete blocker, it would introduce significant breaking changes to existing setups.
That said, there may still be valid use cases for Scoped Custom Elements in Stencil - it just doesn't seem like the right fit for micro-frontend support.
fcano-ut commentedon Apr 3, 2025
Similar to what @sdvg commented, I also run a PoC and couldn't get this to work on React. There's a React issue that tracks this, but it would be a breaking change and it didn't get any attention from maintainers so it doesn't look like it will land in any release soon: react/react#28938
michaelrgalloway commentedon Sep 19, 2025
I'd argue that this is a feature of shadow roots, not the opposite. One of the best selling points for shadow roots is the encapsulation of css. There are several ways to achieve obtaining css rules defined globally into the shadow root. CSS variables or adopted styled sheets for instance. In our micro frontend setup, we take advantage of both and it works out well.
Our use case for scoped custom elements is design component library versions. If one micro app team is on design library version 3.45 and another on version 4.32, then two of the same component name can live on the same web app without collision.
Looking forward to when Stencil supports this feature.
Scoped Custom Elements are currently being implemented in the major browsers. If React or other frameworks have problems with rendering or resolving when inside shadow roots, seems like this is a limitation of the framework, not the standard.
johnjenkins commentedon Dec 18, 2025
hey all - I think most use cases should be covered via #6211 ?
If not lemme know and I'll re-open