Skip to main content
Version: v5 (Preview)

Avoiding Tag Name Clashes

Custom elements are normally defined in one global registry, window.customElements, and each tag name can be defined only once. Defining the same name a second time throws an error.

That's a problem whenever two sets of components with the same tag names end up on one page. Often it's two versions of the same library: the app loads version 1 of @component/library, which defines <my-button>, and its /admin section, or an embedded micro-frontend, loads version 2. Version 2 fails to define <my-button>, and its components don't work.

Stencil gives applications two ways to avoid the clash:

Tag transformationScoped registries
Tag namesChanged, e.g. <my-button> becomes <v2-my-button>Unchanged
CSS selectors and querySelector() stringsNeed the new names, or additionalTagTransformersUnchanged
Where components workAnywhere on the pageOnly in roots that use the registry
Framework supportNone needed beyond using the new tag names, which the framework wrappers supportThe framework must create elements through the registry: a virtual DOM renderer, for example, has to be registry-aware
Browser supportAll browsersNewer browsers