Opened 9 days ago
Closed 8 days ago
#64907 closed defect (bug) (fixed)
Script Modules: Import map can print after classic footer scripts in wp-admin, breaking bare specifier resolution
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Script Loader | Keywords: | has-patch |
| Focuses: | javascript | Cc: |
Description
While testing the new Settings->Connectors and Appearance->Fonts screens we noticed that in some sites nothing was getting loaded and this error came up in the console:
TypeError: Failed to resolve module specifier '@wordpress/boot'
Both _wp_footer_scripts and WP_Script_Modules::print_import_map hook into admin_print_footer_scripts at priority 10. At the same priority, callbacks run in registration order. If a plugin loads admin-filters.php before after_setup_theme fires, _wp_footer_scripts registers first and classic scripts (including inline import() calls) print before the import map. The browser can't resolve bare specifiers without the import map already in the DOM.
Steps to reproduce
- Install WordPress 7.0-beta5
- Create a plugin with this code and activate it (or use Code Snippets):
<?php /** * Plugin Name: Import Map Order Bug Reproducer */ // Loading admin-filters.php during plugin init (before after_setup_theme) // causes _wp_footer_scripts to register on admin_print_footer_scripts // before the Script Modules system registers print_import_map. if ( is_admin() ) { require_once ABSPATH . 'wp-admin/includes/admin-filters.php'; }
- Go to Settings > Connectors or Appearance > Fonts
- Open the browser console — the page is broken with a bare specifier error
Example: The Events Calendar does causes this through its bundled Action Scheduler/admin dependencies (the reason why we found this issue!). Other plugins that load admin utilities early will have the same effect.
Suggested fix
print_import_map should hook at a priority that guarantees it runs before _wp_footer_scripts, regardless of registration order. For example, hooking print_import_map at priority 9 in class-wp-script-modules.php:358 would fix this:
add_action( 'admin_print_footer_scripts', array( $this, 'print_import_map' ), 9 );
Environment
- WordPress 7.0-beta5 (build 62069)
- Reproducible with The Events Calendar 6.15.17.1 or the minimal code snippet above (can be reproduced in Playground)
- Tested locally on macOS/Valet
- Affects both the Connectors screen and the Font Library screen
Attachments (1)
Change History (8)
#2
@
9 days ago
- Milestone changed from Awaiting Review to 7.0
- Version set to trunk
Thanks for the ticket. I assume you tested in Firefox? If not, what browser and version?
#4
@
8 days ago
Hi! I tested in both Zen / Firefox and Chrome browsers.
Zen: 1.19.3b (Firefox 148.0.2) (aarch64)
Chrome: Version 145.0.7632.160 (Official Build) (arm64)
I also attached a screenshot of what it looks like in Playground with Chrome
This ticket was mentioned in PR #11321 on WordPress/wordpress-develop by @mcsf.
8 days ago
#6
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/64907
## Use of AI Tools
I wanted to add something to the description:
Both screens use an inline classic script that calls
import("@wordpress/boot")to bootstrap the page. For this to work, the browser needs the import map (<script type="importmap">) to already be in the DOM. When certain plugins are active, the import map prints *after* the classic scripts instead of before them, so the browser can't resolve the bare specifier.