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.
Issue fork custom_elements-3625091
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
Comment #2
fagoMR attached! Note: I created the MR with help of AI.
Comment #3
fagohere is the MR: https://git.drupalcode.org/project/custom_elements/-/merge_requests/202
Comment #4
fagoI ran regression tests on this and found one difference. drupal-library-locale-translations vanishes on webform routes.
Explained by the AI agent like this:
Proposed fix emit an element for every resolved library even without files.
Comment #5
fagoComment #7
fagoI 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.
Comment #9
fagoThe 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!