Problem

DrupalLibraryElementGenerator::generate() turns a render array's attached libraries into elements. It resolves the dependencies itself but atm ignores weight. Next, it ships drupal-settings of the render-tree, but does not add settings provided via hook_js_settings_build().

This leads to issues when e.g. drupal/ajax library shall be loaded but its settings are missing.

Steps to reproduce

1. Any custom-elements route whose render array attaches core/drupal.dialog.ajax (a form with an AJAX dialog is enough).
2. Render the payload's drupal-library-* elements with the frontend loader (nuxtjs-drupal-ce loadLibrary() / lupus-nuxt3-kickstart's drupal-library--default.vue).
3. Console: the errors above; Drupal.ajax(...) throws on drupalSettings.ajaxTrustedUrl.

Proposed resolution

Build the drupal-library-* elements from AssetResolver::getJsAssets(), so files come in Drupal's real load order across all dependencies. Make the backend ship static settings only for good cache-usage, the frontend owns request state. Add the library_info cache tag and the interface-language and theme cache contexts.

Note: I created the issue with help of AI.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Priority: Minor » Normal
Status: Active » Needs review

MR attached! Note: I created the MR with help of AI.

fago’s picture

fago’s picture

Status: Needs review » Needs work

I ran regression tests on this and found one difference. drupal-library-locale-translations vanishes on webform routes.

Explained by the AI agent like this:

1. Libraries with no declared files — locale/translations has js: {}; the patch emits an element only where files were grouped (if (empty($js[$name])) continue;), so drupal-library-locale-translations vanishes. The old walk emitted the element (empty).

Proposed fix emit an element for every resolved library even without files.

fago’s picture

Issue summary: View changes

fago’s picture

Status: Needs work » Needs review

I figured this feature might not be wanted by everyone, so added #3638044: Add a setting to opt-in to JavaScript library elements to make it opt-in.

  • fago committed 11bddec9 on 3.x
    fix: #3625091 Loaded libraries may miss settings or custom ordering
    
    By...
fago’s picture

Status: Needs review » Fixed

The MR is now updated with this rule:
>Make the backend ship static settings only for good cache-usage, the frontend owns request state.

That is crucial to keep caching working well and this is no perf-regression. Given that, it works as it should now. Merged!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.