Problem/Motivation
The media-library.ui.js library in the default_admin theme is being added to the page before jQuery, one of its dependencies. Screenshot when JS is not aggregated:

This is showing up as a browser console error.

When JS is set to be aggregated, the browser console error still appears.
This is occurring because the weight for media-library.ui.js is set to -1 in default_admin.libraries.yml. This weight can be safely removed, and it should be in preparation for #3467488: Deprecate support for per-file weight in libraries API.
In addition, there are two other libraries (default_admin/init, default_admin/scroll_sync) with weights that should be removed. Removing those can be done here as well.
Steps to reproduce
- Install Drupal with standard profile
- Install Media Library (and Media) modules
- Add a new content type
- Add a media field to the content type
- Create a node of the new type and observe the JS error in the browser console
Proposed resolution
Remove weights from JS file library definitions in the admin theme.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot 2026-10-30 at 2.53.56 PM.png | 123.13 KB | godotislate | |
| Screenshot 2026-10-30 at 2.53.20 PM.png | 12.33 KB | godotislate |
Issue fork drupal-3634443
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:
- 3634443-11
changes, plain diff MR !17667
- 3634443-media-library.ui.js-added-to
changes, plain diff MR !17647
Comments
Comment #2
godotislateComment #4
godotislateRemoved the -1 weight from
default_adminmedia-library.ui.js, and this makes the JS console error go away in manual testing. I added a kernel test to confirm thatmedia-library.ui.jsis added to the page after its dependencies. This test does not explicitly cover the JS console error, nor the behavior when JS files are aggregated. I think this is OK, especially since it means we don't have to add another FJ test to CI run time, but I'm amenable to making a change if wanted.The weight and library actually were added originally to claro in #3023311: Modal dialog style update, and I don't see any explanation why the weight was set. Then subsequently in #3556948: Merging Gin as Admin theme, the library was copied over from claro to the admin theme.
I'm haven't looked into whether there's a more general bug to be addressed if setting a negative weight on a JS library causes it to be added before its dependencies. Explicit weights were removed from most of core in #3568157: Remove explicit weight from CSS files in core.libraries.yml, and so I think it's correct to do here as well. This change also reduces the number of aggregates in the Umami performance tests.
Comment #5
catchComment #6
catchComment #7
godotislate@berdir asked on Slack whether this ticket could be expanded to remove the all the remaining weights for JS files in default_admin.libraries.yml.
Aside from media-library.ui.js, the relevant libraries are:
and
tl;dir: Updated the MR to include removing those weights to see how the tests go.
For
init.js, theweightis set to-99so that it is added to the page as early as possible (to set dark mode, etc.). I'm not finding any other core libraries that haveheader: true, other thandrupal.touchevents-test, though, so I think it should be fine to remove the weight. If contrib or custom libraries also haveheader: trueJS libraries that block init.js loading ASAP, the either the affected site can add a customlibrary_info_alterhook to set the other libraries either to run afterdefault_admin/initor set to load async. Or issues can be filed in the respective contrib modules to update their library definitions as such.The
core/drupalSettingsdependency fordefault_admin/initis a bit strange though, because there is no code in init.js that uses drupalSettings. The dependency was introduced in #3323066: Correctly declare library dependencies to core/drupalSettings, but it's not clear from there why the dependency was added to init specifically. We can probably remove that I think, either here or in a follow up.For
scroll_sync.js, this is used only bydefault_admin/tableheader, so removing the weight should probably be fine. One note is that it was added to Gin in #3293369: Table header overflow issue for multiple user role on permissions page., and it appears to a third-party library, but there's no documentation of where the library came from. We may want to open a follow up for that, because the JS is minified and otherwise can't be maintained.Comment #8
godotislateThe tests, pass so retitled the issue and updated IS.
Comment #9
smustgrave commentedDoes this not need to use the before/after feature now?
Comment #10
godotislateNo, the dependency chain is enough on its own.
Comment #11
smustgrave commentedThis reproducible all the time? I tried following the steps but no error.
Comment #12
godotislate100% reproducible for me.
Comment #13
smustgrave commentedWeird I had to fully delete and restart my ddev but yup I'm seeing the error.
What about
system.adminandadmin.jquery.uiComment #14
berdirThose are css files, lets limit this to JS. Not sure why #3619512: Remove custom weights from default_admin.libraries.yml didn't remove them, maybe there we added/moved after that?
Not a JS expert, but I think this makes sense. Thought about "before" too, if it weren't a header library I think it would make sense to have a before core/drupal so we make sure it's before everything else, but given that header JS is rare I agree this is enough.
Comment #20
catchCommitted/pushed to main and 12.0.x, then I resolved the merge conflict for 11.x in a new MR and cherry-picked to 11.5.x, thanks!
Comment #22
catchComment #23
godotislateCreated the follow-ups I mentioned in #7:
#3635112: Remove core/drupalSettings dependency from default_admin/init library
#3635113: Locate original source of scroll_sync.js