diff --git a/src/wp-includes/build/pages/font-library/page-wp-admin.php b/src/wp-includes/build/pages/font-library/page-wp-admin.php index 4d41be02ae892..440b07f6fdaaa 100644 --- a/src/wp-includes/build/pages/font-library/page-wp-admin.php +++ b/src/wp-includes/build/pages/font-library/page-wp-admin.php @@ -153,11 +153,20 @@ function wp_font_library_wp_admin_enqueue_scripts( $hook_suffix ) { // 2. It initializes the boot module as an inline script. wp_register_script( 'font-library-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true ); - // Add inline script to initialize the app using initSinglePage (no menuItems) + /* + * Add inline script to initialize the app using initSinglePage (no menuItems). + * The dynamic import is deferred until DOMContentLoaded so that all classic + * script dependencies of @wordpress/boot (wp-private-apis, wp-components, + * wp-theme, etc.) have finished parsing and executing before the boot module + * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race + * against the classic-script-printing pass on fast CDN-fronted hosts in + * Chrome, evaluating before wp.theme.privateApis is defined and throwing + * "Cannot unlock an undefined object". See #65103. + */ wp_add_inline_script( 'font-library-wp-admin-prerequisites', sprintf( - 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));', + '(function(){var run=function(){import("@wordpress/boot").then(function(mod){mod.initSinglePage({mountId: "%s", routes: %s});});};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",run);}else{run();}})();', 'font-library-wp-admin-app', wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) diff --git a/src/wp-includes/build/pages/font-library/page.php b/src/wp-includes/build/pages/font-library/page.php index e2849c954ba37..d1cc449155ebd 100644 --- a/src/wp-includes/build/pages/font-library/page.php +++ b/src/wp-includes/build/pages/font-library/page.php @@ -159,12 +159,21 @@ function wp_font_library_render_page() { // 2. It initializes the boot module as an inline script. wp_register_script( 'font-library-prerequisites', '', $asset['dependencies'], $asset['version'], true ); - // Add inline script to initialize the app + /* + * Add inline script to initialize the app. + * The dynamic import is deferred until DOMContentLoaded so that all classic + * script dependencies of @wordpress/boot (wp-private-apis, wp-components, + * wp-theme, etc.) have finished parsing and executing before the boot module + * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race + * against the classic-script-printing pass on fast CDN-fronted hosts in + * Chrome, evaluating before wp.theme.privateApis is defined and throwing + * "Cannot unlock an undefined object". See #65103. + */ $init_modules = []; wp_add_inline_script( 'font-library-prerequisites', sprintf( - 'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));', + '(function(){var run=function(){import("@wordpress/boot").then(function(mod){mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"});});};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",run);}else{run();}})();', 'font-library-app', wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), diff --git a/src/wp-includes/build/pages/options-connectors/page-wp-admin.php b/src/wp-includes/build/pages/options-connectors/page-wp-admin.php index 3f3048b8fb98b..3f31e5557d3fb 100644 --- a/src/wp-includes/build/pages/options-connectors/page-wp-admin.php +++ b/src/wp-includes/build/pages/options-connectors/page-wp-admin.php @@ -153,11 +153,20 @@ function wp_options_connectors_wp_admin_enqueue_scripts( $hook_suffix ) { // 2. It initializes the boot module as an inline script. wp_register_script( 'options-connectors-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true ); - // Add inline script to initialize the app using initSinglePage (no menuItems) + /* + * Add inline script to initialize the app using initSinglePage (no menuItems). + * The dynamic import is deferred until DOMContentLoaded so that all classic + * script dependencies of @wordpress/boot (wp-private-apis, wp-components, + * wp-theme, etc.) have finished parsing and executing before the boot module + * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race + * against the classic-script-printing pass on fast CDN-fronted hosts in + * Chrome, evaluating before wp.theme.privateApis is defined and throwing + * "Cannot unlock an undefined object". See #65103. + */ wp_add_inline_script( 'options-connectors-wp-admin-prerequisites', sprintf( - 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));', + '(function(){var run=function(){import("@wordpress/boot").then(function(mod){mod.initSinglePage({mountId: "%s", routes: %s});});};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",run);}else{run();}})();', 'options-connectors-wp-admin-app', wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) diff --git a/src/wp-includes/build/pages/options-connectors/page.php b/src/wp-includes/build/pages/options-connectors/page.php index 6009dbb2570a9..b0e49b11e2834 100644 --- a/src/wp-includes/build/pages/options-connectors/page.php +++ b/src/wp-includes/build/pages/options-connectors/page.php @@ -159,12 +159,21 @@ function wp_options_connectors_render_page() { // 2. It initializes the boot module as an inline script. wp_register_script( 'options-connectors-prerequisites', '', $asset['dependencies'], $asset['version'], true ); - // Add inline script to initialize the app + /* + * Add inline script to initialize the app. + * The dynamic import is deferred until DOMContentLoaded so that all classic + * script dependencies of @wordpress/boot (wp-private-apis, wp-components, + * wp-theme, etc.) have finished parsing and executing before the boot module + * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race + * against the classic-script-printing pass on fast CDN-fronted hosts in + * Chrome, evaluating before wp.theme.privateApis is defined and throwing + * "Cannot unlock an undefined object". See #65103. + */ $init_modules = []; wp_add_inline_script( 'options-connectors-prerequisites', sprintf( - 'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));', + '(function(){var run=function(){import("@wordpress/boot").then(function(mod){mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"});});};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",run);}else{run();}})();', 'options-connectors-app', wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),