Install
Works with Drupal: ^11 || ^12Using Composer to manage Drupal site dependencies
Alternative installation files
Release notes
The first stable release of Web Component Runtime: the shared runtime that makes web component libraries work in Drupal. A library module or theme registers with it through a data file and carries no runtime code of its own. Libraries generated by Custom Elements Manifest to SDC Generator, such as Cordwainer Elements from 1.1.0, depend on it.
Features
- Library registry. An extension registers its libraries in
<extension>.web_component_runtime.yml, validated against registry schema 1 (schema/web_component_runtime.schema.json). Each library is validated on its own, so an invalid one is logged to theweb_component_runtimechannel and left out without taking the rest of its file with it. Other modules read the result throughLibraryRegistryInterface. - One import map per page. The map is added only to responses that load a registered library, directly or as a dependency, and goes first in the page's
<head>content. AJAX responses, BigPipe placeholders included, add the entries a page doesn't define yet through an AJAX command. - Scoped entries. A library's imports apply only to modules under its
scope, so two libraries can ship different versions of the same dependency. An entry markedglobal: truegoes in the map's top-level imports. A scope whose path core URL-encodes is listed under both URLs. - Conflict detection. When two libraries map the same specifier to different addresses in the top-level imports, or within one scope, the library registered first keeps it, and the conflict is logged.
- Content Security Policy. With the Content-Security-Policy module installed, the map carries the response's nonce and the nonce is added to the policy's
script-src, unless the policy already allows inline scripts. A map added by AJAX uses the nonce of the page it lands on. The module isn't required. - Named slots in Twig. The
slot_namefilter assigns a slot's content to a custom element's named slot, as in{% apply slot_name('primary-navigation') %}. It scans the rendered HTML as text, so render and BigPipe placeholders stay intact. Thehas_slot_contenttest tells whether a slot prints anything a browser shows, so a template can leave an empty slot out and let the element show its fallback content. - Older generated libraries keep working. A map attached by a library generated before the generator targeted this module, such as Cordwainer Elements 1.0.x, is merged into the runtime's map, and such a library's own
slot_namefilter gives identical output.
Requirements
- Drupal
^11 || ^12. - Browsers that support custom elements, ES modules and import maps.
Registry schema 1 is stable
A change that isn't backwards compatible will come as schema 2. A key the installed runtime doesn't know fails validation, so a misspelled key is reported instead of being silently dropped. A library that uses a field added in a later release raises its drupal/web_component_runtime constraint to that release.
The optional fields base_path, loader, tags, categories, form_controls, events and color_scheme are validated and passed on through the registry, but this release doesn't act on them yet.
Known limitations
- Browsers before Chrome 133, Safari 18.4 and Firefox 150 honor only the first import map, and accept one added by AJAX only while no module script has loaded yet.
- A page that renders a Canvas code component next to a registered library's component gets two import maps, Canvas's and the runtime's, until #3627762 hands the entries to Canvas. Canvas pages without code components get only the runtime's map.
- A library's module scripts have to load from under its
scope. Core never aggregates them, but ahook_js_alter()implementation or contributed aggregator that does breaks their bare imports.
Upgrading from 1.0.0-alpha1
No code changes. The README now documents the module instead of its development roadmap.
Issues in this release
- #3627747: Scaffold the module with info file, composer.json and GitLab CI
- #3627749: Define the library registry file and its discovery
- #3627751: Emit one aggregated import map
- #3627752: Scope each library's import map entries and detect global specifier conflicts
- #3627753: Add a CSP nonce to the import map
- #3627754: Provide the slot_name Twig filter and has_slot_content test
- #3627947: Prepare and publish the 1.0.0 release