Skip to content

Commit a29e538

Browse files
lezamaclaude
andauthored
Forms: Fix black screen when The Events Calendar is active (#47823)
The wp-build generated page-wp-admin.php uses import("@wordpress/boot") inside a regular inline script. This relies on the browser importmap being in the DOM before the inline script executes. However, WordPress outputs the importmap AFTER regular footer scripts (position 107 vs 100 in the DOM), making it fragile — it works by accident in most setups due to browser microtask timing. Plugins like The Events Calendar (via StellarWP) disrupt this timing by converting scripts to type="module" via script_loader_tag, causing the import() call to fail and leaving the Forms dashboard as a black screen. Fix: Replace the inline import() with a two-step approach: 1. A plain global config (window.__jetpackFormsBootConfig) set by the regular inline script — no module specifiers needed. 2. An inline <script type="module"> printed at priority 20 of admin_print_footer_scripts (after the importmap at priority 9), which imports @wordpress/boot and calls initSinglePage with the config — guaranteed to resolve because modules execute after the importmap. The upstream fix will go into @wordpress/build's page-wp-admin.php template to fix this for all consumers. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent da8f0c3 commit a29e538

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fix Forms dashboard black screen when The Events Calendar is active by replacing fragile import() in inline script with a proper script module.

projects/packages/forms/src/dashboard/class-dashboard.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,66 @@ public static function load_wp_build() {
5959
}
6060
}
6161

62+
/**
63+
* Fix import map ordering for the wp-build boot script.
64+
*
65+
* In wp-admin, _wp_footer_scripts (classic scripts) and print_import_map
66+
* both hook into admin_print_footer_scripts at priority 10, but
67+
* _wp_footer_scripts is registered first. This causes the inline
68+
* import("@wordpress/boot") to execute before the import map exists.
69+
*
70+
* This fix moves the import() call from the classic inline script to a
71+
* <script type="module"> printed at priority 20 (after the import map).
72+
*
73+
* @todo Remove once @wordpress/build ships with the loader.js fix upstream
74+
* (WordPress/gutenberg#76870) and Jetpack updates the dependency.
75+
*/
76+
public static function fix_boot_import_map_ordering() {
77+
$handle = self::FORMS_WPBUILD_ADMIN_SLUG . '-prerequisites';
78+
79+
add_action(
80+
'admin_enqueue_scripts',
81+
static function () use ( $handle ) {
82+
if ( ! Dashboard::is_jetpack_forms_admin_page() ) {
83+
return;
84+
}
85+
86+
$data = wp_scripts()->get_data( $handle, 'after' );
87+
if ( empty( $data ) ) {
88+
return;
89+
}
90+
91+
// Find and extract the import("@wordpress/boot") inline script.
92+
$boot_script = null;
93+
$remaining = array();
94+
foreach ( $data as $line ) {
95+
if ( strpos( $line, '@wordpress/boot' ) !== false ) {
96+
$boot_script = $line;
97+
} else {
98+
$remaining[] = $line;
99+
}
100+
}
101+
102+
if ( $boot_script === null ) {
103+
return;
104+
}
105+
106+
// Remove from the classic script handle.
107+
wp_scripts()->add_data( $handle, 'after', $remaining );
108+
109+
// Re-emit as a module script after the import map.
110+
add_action(
111+
'admin_print_footer_scripts',
112+
static function () use ( $boot_script ) {
113+
wp_print_inline_script_tag( $boot_script, array( 'type' => 'module' ) );
114+
},
115+
20
116+
);
117+
},
118+
PHP_INT_MAX
119+
);
120+
}
121+
62122
/**
63123
* Script handle for the JS file we enqueue in the Feedback admin page.
64124
*
@@ -97,6 +157,7 @@ public function init() {
97157

98158
if ( $is_wp_build_enabled ) {
99159
self::load_wp_build();
160+
self::fix_boot_import_map_ordering();
100161
}
101162

102163
add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_scripts' ) );

0 commit comments

Comments
 (0)