Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix Forms dashboard black screen when The Events Calendar is active by replacing fragile import() in inline script with a proper script module.
61 changes: 61 additions & 0 deletions projects/packages/forms/src/dashboard/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,66 @@ public static function load_wp_build() {
}
}

/**
* Fix import map ordering for the wp-build boot script.
*
* In wp-admin, _wp_footer_scripts (classic scripts) and print_import_map
* both hook into admin_print_footer_scripts at priority 10, but
* _wp_footer_scripts is registered first. This causes the inline
* import("@wordpress/boot") to execute before the import map exists.
*
* This fix moves the import() call from the classic inline script to a
* <script type="module"> printed at priority 20 (after the import map).
*
* @todo Remove once @wordpress/build ships with the loader.js fix upstream
* (WordPress/gutenberg#76870) and Jetpack updates the dependency.
*/
public static function fix_boot_import_map_ordering() {
$handle = self::FORMS_WPBUILD_ADMIN_SLUG . '-prerequisites';

add_action(
'admin_enqueue_scripts',
static function () use ( $handle ) {
if ( ! Dashboard::is_jetpack_forms_admin_page() ) {
return;
}

$data = wp_scripts()->get_data( $handle, 'after' );
if ( empty( $data ) ) {
return;
}

// Find and extract the import("@wordpress/boot") inline script.
$boot_script = null;
$remaining = array();
foreach ( $data as $line ) {
if ( strpos( $line, '@wordpress/boot' ) !== false ) {
$boot_script = $line;
} else {
$remaining[] = $line;
}
}

if ( $boot_script === null ) {
return;
}

// Remove from the classic script handle.
wp_scripts()->add_data( $handle, 'after', $remaining );

// Re-emit as a module script after the import map.
add_action(
'admin_print_footer_scripts',
static function () use ( $boot_script ) {
wp_print_inline_script_tag( $boot_script, array( 'type' => 'module' ) );
},
20
);
},
PHP_INT_MAX
);
}

/**
* Script handle for the JS file we enqueue in the Feedback admin page.
*
Expand Down Expand Up @@ -97,6 +157,7 @@ public function init() {

if ( $is_wp_build_enabled ) {
self::load_wp_build();
self::fix_boot_import_map_ordering();
}

add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_scripts' ) );
Expand Down
Loading