Resolve #3638044: Add a setting to opt-in to JavaScript library elements

Claude Code: opened on behalf of fago. Stacked on !205 (merged): this branch contains the commits of !205 (merged) plus one commit, "library elements setting". Until !205 (merged) is merged, the diff shows both.

Issue #3638044

Problem

CustomElement::setSlotFromRenderArray() adds <drupal-library-*> elements for every render array with attached JavaScript libraries. Sites whose frontend does not load Drupal's JavaScript get a larger payload they do not use, and cannot turn it off.

Solution

  • New boolean library_elements in custom_elements.settings, off by default: install config, schema, checkbox in the settings form, custom_elements_update_9403() for existing sites.
  • DrupalLibraryElementGenerator::generate() returns no elements while the setting is off. A missing key counts as off.
  • setSlotFromRenderArray() adds config:custom_elements.settings to the element whenever the render array attaches libraries, so toggling the setting invalidates output built in either state.
  • README section describing the library elements.

Testing

  • New DrupalLibraryElementSettingTest (kernel): off by default with unchanged markup, missing key is off, on, cache tag in both states, the update function.
  • DrupalLibraryElementTest enables the setting in setUp().

AI-Generated: Yes (Claude Code wrote the setting commit and this text.)

Merge request reports

Loading
Loading