Make WordPress Core

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: mlaetitia's profile mlaetitia Owned by: mcsf's profile mcsf
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

  1. Install WordPress 7.0-beta5
  2. 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';
}
  1. Go to Settings > Connectors or Appearance > Fonts
  2. 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)

Xnip2026-03-20_12-15-15.jpg (238.4 KB) - added by mlaetitia 8 days ago.
Connectors Screen empty

Download all attachments as: .zip

Change History (8)

#1 @mlaetitia
9 days ago

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.

#2 @westonruter
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?

#3 @westonruter
9 days ago

  • Keywords reporter-feedback added

@mlaetitia
8 days ago

Connectors Screen empty

#4 @mlaetitia
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

#5 @mlaetitia
8 days ago

  • Keywords reporter-feedback removed

Removing reporter-feedback keyword

#7 @mcsf
8 days ago

  • Owner set to mcsf
  • Resolution set to fixed
  • Status changed from new to closed

In 62080:

Script Loader: Print import map before classic scripts.

Should any scripts contain calls to import(), the browser won't be able to resolve bare import specifiers unless the import map is already in the DOM. Thus, rather than rely on hook registration order, which is fallible, ensure that the newer callback WP_Script_Modules::print_import_map (since 6.5.0) has a lower priority than _wp_footer_scripts.

Reviewed by jonsurrell.
Props mlaetitia.
Fixes #64907.

Note: See TracTickets for help on using tickets.