[wp-trac] [WordPress Trac] #61500: Script Modules: Allow scripts to depend on modules
WordPress Trac
noreply at wordpress.org
Wed Feb 4 01:41:43 UTC 2026
#61500: Script Modules: Allow scripts to depend on modules
-------------------------------------+-------------------------------------
Reporter: jonsurrell | Owner: westonruter
Type: enhancement | Status: closed
Priority: normal | Milestone: 7.0
Component: Script Loader | Version: 6.5
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit- | Focuses: javascript,
tests commit needs-dev-note | performance
-------------------------------------+-------------------------------------
Changes (by westonruter):
* status: accepted => closed
* resolution: => fixed
Comment:
In [changeset:"61587" 61587]:
{{{
#!CommitTicketReference repository="" revision="61587"
Script Loader: Allow classic scripts to depend on script modules.
This allows classic scripts to declare dependencies on script modules by
passing `module_dependencies` in the `$args` param for
`wp_register_script()` or `wp_enqueue_script()`. The
`WP_Script_Modules::get_import_map()` method is updated to traverse the
dependency tree of all enqueued classic scripts to find any associated
script module dependencies and include them in the `importmap`, enabling
dynamic imports of modules within classic scripts.
A `_wp_scripts_add_args_data()` helper function is introduced to
consolidate argument validation and processing for `wp_register_script()`
and `wp_enqueue_script()`, reducing code duplication. This function
validates that the `$args` array only contains recognized keys
(`strategy`, `in_footer`, `fetchpriority`, `module_dependencies`) and
triggers a `_doing_it_wrong()` notice for any unrecognized keys.
Similarly, `WP_Scripts::add_data()` is updated to do early type checking
for the data passed to `$args`. The script modules in
`module_dependencies` may be referenced by a module ID string or by an
array that has an `id` key, following the same pattern as dependencies in
`WP_Script_Modules`.
When a script module is added to the `module_dependencies` for a classic
script, but it does not exist at the time the `importmap` is printed, a
`_doing_it_wrong()` notice is emitted.
Developed in https://github.com/WordPress/wordpress-develop/pull/8024
Follow-up to [61323].
Props sirreal, westonruter.
See #64229.
Fixes #61500.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61500#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list