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

Whether single-spa can support multiple versions of same custom elements from different micro frontends loaded in SPA #1078

Closed
msbasanth opened this issue Dec 21, 2022 · 2 comments

Comments

@msbasanth
Copy link

Basic problem: Name collision in custom elements (LitElement) due to global registry @window level.
The CustomElementRegistry provides methods for registering custom elements. One of the limitations of working with this global registry is that multiple versions of the same element cannot co-exist.

Here we have two custom elements my-web-component but different versions are used in different extensions.
image

To Reproduce
Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "my-web-component" has already been used with this registry.
The problem is that CustomElementRegistry is a global window object

window.customElements.define('my-web-component', MyWebComponent);

Expected behavior
Whether single-spa can solve the basic problem of tag name conflict when multiple versions of the same custom elements are used in micro frontend UIs?

Regards
Basanth

@filoxo
Copy link
Contributor

filoxo commented Dec 21, 2022

My initial inclination is that no, single-spa cannot help with this at all. single-spa is a client-side routing library. Custom Element Registry naming collisions is a problem inherent to Custom Elements and browser environments, and afaik Custom Elements do not have an unregister API. Maybe the information at WICG/webcomponents#716 and https://open-wc.org/docs/development/scoped-elements/ can be more helpful.

If CustomElements could be unregistered, it'd be implemented much the same was as single-spa-leaked-globals and would still have the limitation of allowing only a single instance of a component registered at a time.

@msbasanth
Copy link
Author

Thanks for the quick reply and confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants