Skip to content

Document scoped customElementRegistry and related properties#43149

Merged
hamishwillee merged 6 commits intomdn:mainfrom
pepelsbey:custom-element-registry
Feb 22, 2026
Merged

Document scoped customElementRegistry and related properties#43149
hamishwillee merged 6 commits intomdn:mainfrom
pepelsbey:custom-element-registry

Conversation

@pepelsbey
Copy link
Member

@pepelsbey pepelsbey commented Feb 17, 2026

Description

New pages

  • API/CustomElementRegistry/CustomElementRegistry — The CustomElementRegistry() constructor
  • API/CustomElementRegistry/initialize — The initialize() method
  • API/Document/customElementRegistry — The customElementRegistry property on Document
  • API/Element/customElementRegistry — The customElementRegistry property on Element
  • API/ShadowRoot/customElementRegistry — The customElementRegistry property on ShadowRoot
  • API/HTMLTemplateElement/shadowRootCustomElementRegistry — The shadowRootCustomElementRegistry property on HTMLTemplateElement

Updated pages

  • API/CustomElementRegistry — Added constructor section and initialize() to the list of instance methods
  • API/ShadowRoot — Added customElementRegistry to the list of instance properties
  • API/HTMLTemplateElement — Added shadowRootCustomElementRegistry to the list of instance properties
  • HTML/Reference/Elements/template — Added shadowrootcustomelementregistry to the list of <template> attributes

Motivation

Document the scoped custom element registries API supported in Safari 26 and Chrome Canary

Additional details

⚠️ The <template shadowrootcustomelementregistry> attribute is not currently listed in BCD but I tested and it seems to work in Safari and Chrome Canary.

@pepelsbey pepelsbey requested review from a team as code owners February 17, 2026 13:01
@pepelsbey pepelsbey requested review from hamishwillee and removed request for a team February 17, 2026 13:01
@github-actions github-actions bot added Content:HTML Hypertext Markup Language docs Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Feb 17, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2026

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: /en-US/docs/Web/API/CustomElementRegistry/upgrade
Title: CustomElementRegistry: upgrade() method
Flaw count: 3

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/HTMLElement/connectedCallback which doesn't resolve
    • Macro domxref produces link /en-US/docs/Web/API/HTMLElement/observedAttributes which doesn't resolve
    • Macro domxref produces link /en-US/docs/Web/API/HTMLElement/attributeChangedCallback which doesn't resolve

URL: /en-US/docs/Web/API/ShadowRoot
Title: ShadowRoot
Flaw count: 1

  • macros:
    • Macro domxref produces link /en-US/docs/Web/API/ShadowRoot/getSelection which doesn't resolve

URL: /en-US/docs/Web/API/Web_components
Title: Web Components
Flaw count: 3

  • macros:
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_custom_elements which is a redirect
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_shadow_DOM which is a redirect
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_templates_and_slots which is a redirect

URL: /en-US/docs/Web/API/Web_components/Using_custom_elements
Title: Using custom elements
Flaw count: 3

  • macros:
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_custom_elements which is a redirect
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_shadow_DOM which is a redirect
    • Macro defaultapisidebar produces link /en-US/docs/Web/Web_Components/Using_templates_and_slots which is a redirect

(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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" To get an instance of it, use the {{domxref("window.customElements")}} property. " is now not the only way.


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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Collaborator

@hamishwillee hamishwillee Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO This should be inverted, and you should explain what you mean by scope. So something like

Suggested change
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.

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@github-actions github-actions bot added size/l [PR only] 501-1000 LoC changed and removed size/m [PR only] 51-500 LoC changed labels Feb 20, 2026
@pepelsbey
Copy link
Member Author

pepelsbey commented Feb 20, 2026

@hamishwillee good points! There you go:

Ouch, it was M, now it’s L 😬


None ({{jsxref("undefined")}}).

## Description
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so useful!

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepelsbey Looks great, and as a bonus I learned about uprading, which I had been fuzzy on.

@hamishwillee hamishwillee merged commit 9c4d4cb into mdn:main Feb 22, 2026
8 checks passed
wbamberg added a commit to wbamberg/content that referenced this pull request Feb 26, 2026
* 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)
  ...
@pepelsbey pepelsbey deleted the custom-element-registry branch February 27, 2026 15:31
jdatapple pushed a commit to jdatapple/content that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTML Hypertext Markup Language docs Content:WebAPI Web API docs size/l [PR only] 501-1000 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants