Document scoped customElementRegistry and related properties#43149
Document scoped customElementRegistry and related properties#43149hamishwillee merged 6 commits intomdn:mainfrom
Conversation
Preview URLs (17 pages)
Flaws (10)Note! 13 documents with no flaws that don't need to be listed. 🎉 Found an unexpected or unresolvable flaw? Please report it here. URL:
URL:
URL:
URL:
(comment last updated: 2026-02-20 16:45:28) |
| {{APIRef("Web Components")}} | ||
|
|
||
| The **`CustomElementRegistry`** interface provides methods for registering custom elements and querying registered elements. To get an instance of it, use the {{domxref("window.customElements")}} property. | ||
| The **`CustomElementRegistry`** interface provides methods for registering custom elements and querying registered elements. To get an instance of it, use the {{domxref("window.customElements")}} property. To create a scoped registry, use the {{domxref("CustomElementRegistry.CustomElementRegistry()", "CustomElementRegistry()")}} constructor. |
There was a problem hiding this comment.
" To get an instance of it, use the {{domxref("window.customElements")}} property. " is now not the only way.
files/en-us/web/api/htmltemplateelement/shadowrootcustomelementregistry/index.md
Outdated
Show resolved
Hide resolved
|
|
||
| A shadow root's `customElementRegistry` determines which [custom element](/en-US/docs/Web/API/Web_components/Using_custom_elements) definitions are used for upgrading elements within that shadow tree. It can be set when the shadow root is created via the `customElementRegistry` option of {{domxref("Element.attachShadow()")}}, or later using {{domxref("CustomElementRegistry.initialize()")}}. Once set to a `CustomElementRegistry` object, it cannot be changed. | ||
|
|
||
| This property is also available on {{domxref("Document")}} objects via the same `customElementRegistry` property name. |
There was a problem hiding this comment.
If you accepted my comment on the Window variant of this property, make customElementRegistry a cross link.
|
|
||
| {{APIRef("Web Components")}} | ||
|
|
||
| The **`initialize()`** method of the {{domxref("CustomElementRegistry")}} interface associates this registry with a DOM subtree, setting the {{domxref("Element.customElementRegistry", "customElementRegistry")}} of each inclusive descendant that doesn't already have one, and attempting to upgrade any [custom elements](/en-US/docs/Web/API/Web_components/Using_custom_elements) found. |
There was a problem hiding this comment.
My only concern here is that I don't know what upgrading is. Further down you link to https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/upgrade but that doesn't say what upgrading actually does either.
IN theory it is out of scope but you lean heavily on the definition, so if you are able would love a fix to https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/upgrade
|
|
||
| The **`CustomElementRegistry()`** constructor creates a new {{domxref("CustomElementRegistry")}} object for scoped usage. | ||
|
|
||
| The global `CustomElementRegistry` object associated with a {{domxref("Window")}} is not created using this constructor; it is automatically created when the window is set up, and is accessible via the {{domxref("window.customElements")}} property. The `CustomElementRegistry()` constructor is specifically for creating scoped registries that limit [custom element](/en-US/docs/Web/API/Web_components/Using_custom_elements) definitions to a particular scope. |
There was a problem hiding this comment.
IMO This should be inverted, and you should explain what you mean by scope. So something like
| The global `CustomElementRegistry` object associated with a {{domxref("Window")}} is not created using this constructor; it is automatically created when the window is set up, and is accessible via the {{domxref("window.customElements")}} property. The `CustomElementRegistry()` constructor is specifically for creating scoped registries that limit [custom element](/en-US/docs/Web/API/Web_components/Using_custom_elements) definitions to a particular scope. | |
| The constructor is specifically used for creating scoped registries that limit [custom element](/en-US/docs/Web/API/Web_components/Using_custom_elements) definitions to a particular scope, such as an element or {{domxref("ShadowRoot")}}. | |
| Note that the global `CustomElementRegistry` object associated with a {{domxref("Window")}} is not created using this constructor; it is automatically created when the window is set up, and is accessible via the {{domxref("window.customElements")}} property. |
hamishwillee
left a comment
There was a problem hiding this comment.
@pepelsbey Love this. Just a few suggestion.
I do think we should update https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements to at least mention this, and possibly also the top level https://developer.mozilla.org/en-US/docs/Web/API/Web_components
Were you planning on doing that?
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
|
@hamishwillee good points! There you go: Ouch, it was M, now it’s L 😬 |
|
|
||
| None ({{jsxref("undefined")}}). | ||
|
|
||
| ## Description |
hamishwillee
left a comment
There was a problem hiding this comment.
@pepelsbey Looks great, and as a bonus I learned about uprading, which I had been fuzzy on.
* upstream/main: (619 commits) Fix usage of numbers iterator in zip example (mdn#43236) Synchronize with BCD v7.3.3 (mdn#43178) Add Firefox 148 sanitizer release note (mdn#43234) WebDriver conformance changes for Firefox 148 (mdn#43228) ci(auto-merge): fix target-repo (mdn#43139) Add session mgt guide (mdn#42908) docs(firefox-release): Finalize release notes for Fx148 release (mdn#43225) [Technical Review] Add folder for WebDriver BiDi and create initial landing pages (mdn#43153) fix: correct 'after' to 'before' in break-before always/all descriptions (mdn#43185) added the release note for position-try-order (mdn#43223) Clarify that role="button" does not inherit button functionality (mdn#43186) Fix wording mistake in Temporal.ZonedDateTime (mdn#43188) Fix description for break-before: always (mdn#43190) improve confusing sentance (mdn#43172) Document scoped customElementRegistry and related properties (mdn#43149) fix: correct terminology for object initializer property names (mdn#43182) Fix typo about arrow function expression body (mdn#43175) Update InterfaceData based on WebRef (mdn#43179) Fix clarify visibilitychange event intro to mention all triggers (mdn#43177) [WebExtensions] Document runtime.getVersion() method (mdn#42971) ...
Description
New pages
API/CustomElementRegistry/CustomElementRegistry— TheCustomElementRegistry()constructorAPI/CustomElementRegistry/initialize— Theinitialize()methodAPI/Document/customElementRegistry— ThecustomElementRegistryproperty onDocumentAPI/Element/customElementRegistry— ThecustomElementRegistryproperty onElementAPI/ShadowRoot/customElementRegistry— ThecustomElementRegistryproperty onShadowRootAPI/HTMLTemplateElement/shadowRootCustomElementRegistry— TheshadowRootCustomElementRegistryproperty onHTMLTemplateElementUpdated pages
API/CustomElementRegistry— Added constructor section andinitialize()to the list of instance methodsAPI/ShadowRoot— AddedcustomElementRegistryto the list of instance propertiesAPI/HTMLTemplateElement— AddedshadowRootCustomElementRegistryto the list of instance propertiesHTML/Reference/Elements/template— Addedshadowrootcustomelementregistryto the list of<template>attributesMotivation
Document the scoped custom element registries API supported in Safari 26 and Chrome Canary
Additional details
<template shadowrootcustomelementregistry>attribute is not currently listed in BCD but I tested and it seems to work in Safari and Chrome Canary.CustomElementRegistryinterfaceinitialize()methodDocumentOrShadowRoot.customElementRegistryElement.customElementRegistryHTMLTemplateElement.shadowRootCustomElementRegistry<template shadowrootcustomelementregistry>