Install
Works with Drupal: ^11 || ^12Using Composer to manage Drupal site dependencies
Alternative installation files
Release notes
1.2.0 integrates with Drupal Canvas through a new submodule, web_component_runtime_canvas, and moves the base path handover from the import map onto each library's own scripts, so a base path reaches every document its library does. Registry files don't change, so 1.1 libraries keep working.
New features
- Canvas submodule (#3627761). Everything Canvas-specific lives in
web_component_runtime_canvas, which depends on Canvas, so Canvas stays optional for registered libraries. Enable it on sites that use Canvas. - One import map on Canvas pages (#3627762). On a page with a registered library, the submodule folds Canvas's own import map into the runtime's, so a page with a Canvas code component and a registered library's component has one map instead of two. Canvas's entries win a conflict, its
modulepreloadlinks stay for its own entries only, and the map keeps its CSP nonce. A page with no registered library keeps Canvas's map as before. - Import maps in component previews (#3627762). Canvas's Library hover previews get the registry's entries, the
<head>script and, for a lazy library, the lazy loader, so a registered library's components upgrade there. - Base paths through the library's scripts (#3627762). A library with
base_path_api: { attribute: data-… }gets the attribute on its own first script, or on the lazy loader's in lazy mode. A library with{ module: …, export: … }gets a module script served from/web-component-runtime/base-path/{library}, loaded right before its own, which calls the setter. Both reach full pages, AJAX responses, BigPipe placeholders and Canvas previews.
Upgrading
- On a site with Canvas, enable
web_component_runtime_canvasand export your configuration. Canvas component versions don't change, since Canvas computes them from a component's source settings, slots and props only. - Rebuild caches after updating, so Canvas rebuilds its Library previews. Base path URLs are fixed when Drupal builds its script cache, so a site moved to another base path needs its caches rebuilt too.
- Libraries don't need changes.
base_pathandbase_path_apiwork as before. An attribute library has to look for its attribute on any<script>, as Shoelace-style libraries and cw-elements do. One that only reads it from the import map's element should use a setter instead. - Code that uses the runtime's classes directly:
ImportMapno longer has$basePathAttributes,$basePathSettersorhasBasePaths(),HtmlHeadImportMapEmitter::SETTER_KEY_PREFIXis gone, and the AJAX import map command's data no longer carriesbasePathAttributesorbasePathSetters.ImportMapBuildergainsurl()andpageAttachments().
Content Security Policy
With the Content-Security-Policy module, the import map still carries the response's nonce, Canvas pages included. Base path setters are now ordinary same-origin script files instead of inline scripts, so they need no nonce: a policy that allows 'self' for scripts allows them.
Requirements
Drupal 11 or 12, with no new dependencies. The Canvas submodule needs Drupal 11.3 or later and Canvas, which Composer doesn't install for you.
See the README's "Canvas" and "Base paths" sections for details.