PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | build/pages/dashboard/page-wp-admin.php +78 -16 23.1.0 → trunk View file →
@@ -86,11 +86,12 @@
86 86 * Automatically called during page rendering.
87 87 */
88 88 function gutenberg_dashboard_wp_admin_preload_data() {
89 89 // Define paths to preload - same for all pages
90 - // Please also change packages/core-data/src/entities.js when changing this.
90 + // This must exactly match the _fields list in packages/core-data/src/entities.js,
91 + // same fields in the same order, or the preload is never consumed.
91 92 $preload_paths = array(
92 - '/?_fields=description,gmt_offset,home,image_sizes,image_size_threshold,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
93 + '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
93 94 array( '/wp/v2/settings', 'OPTIONS' ),
94 95 );
95 96
96 97 // Use rest_preload_api_request to gather the preloaded data
@@ -133,9 +134,11 @@
133 134
134 135 // Load build constants
135 136 $build_constants = require __DIR__ . '/../../constants.php';
136 137
137 - // Fire init action for extensions to register routes and menu items
138 + /**
139 + * Fires when the dashboard admin page is initialized so extensions can register routes and menu items.
140 + */
138 141 do_action( 'dashboard-wp-admin_init' );
139 142
140 143 // Preload REST API data
141 144 gutenberg_dashboard_wp_admin_preload_data();
@@ -142,10 +145,14 @@
142 145
143 146 // Get all registered routes
144 147 $routes = gutenberg_get_dashboard_wp_admin_routes();
145 148
146 - // Get boot module asset file for dependencies
149 + // Get boot module asset file for dependencies. Plugins that build their own
150 + // boot module use it; everyone else falls back to the copy bundled with Core.
147 151 $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
152 + if ( ! file_exists( $asset_file ) ) {
153 + $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
154 + }
148 155 if ( file_exists( $asset_file ) ) {
149 156 $asset = require $asset_file;
150 157
151 158 // This script serves two purposes:
@@ -152,15 +159,41 @@
152 159 // 1. It ensures all the globals that are made available to the modules are loaded.
153 160 // 2. It initializes the boot module as an inline script.
154 161 wp_register_script( 'dashboard-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
155 162
156 - // Add inline script to initialize the app using initSinglePage (no menuItems)
163 + $init_modules = ["@wordpress/dashboard-init"];
164 +
165 + /*
166 + * Add inline script to initialize the app using initSinglePage (no menuItems).
167 + * The dynamic import is deferred until DOMContentLoaded so that all classic
168 + * script dependencies of @wordpress/boot (wp-private-apis, wp-components,
169 + * wp-theme, etc.) have finished parsing and executing before the boot module
170 + * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race
171 + * against the classic-script-printing pass on fast CDN-fronted hosts in
172 + * Chrome, evaluating before wp.theme.privateApis is defined and throwing
173 + * "Cannot unlock an undefined object". See <https://core.trac.wordpress.org/ticket/65103>.
174 + */
175 + $init_js_function = <<<'JS'
176 + ( mountId, routes, initModules ) => {
177 + const run = async () => {
178 + const mod = await import( "@wordpress/boot" );
179 + mod.initSinglePage( { mountId, routes, initModules } );
180 + };
181 + if ( document.readyState === "loading" ) {
182 + document.addEventListener( "DOMContentLoaded", run );
183 + } else {
184 + run();
185 + }
186 + }
187 + JS;
157 188 wp_add_inline_script(
158 189 'dashboard-wp-admin-prerequisites',
159 190 sprintf(
160 - 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));',
161 - 'dashboard-wp-admin-app',
162 - wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
191 + '( %s )( %s, %s, %s );',
192 + $init_js_function,
193 + wp_json_encode( 'dashboard-wp-admin-app', JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
194 + wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
195 + wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
163 196 )
164 197 );
165 198
166 199 // Register prerequisites style by filtering script dependencies to find registered styles
@@ -179,8 +212,11 @@
179 212 'id' => '@wordpress/boot',
180 213 ),
181 214 );
182 215
216 + // Add init modules as static dependencies
217 + $boot_dependencies[] = array( 'import' => 'static', 'id' => '@wordpress/dashboard-init' );
218 +
183 219 // Add all registered routes as dependencies
184 220 foreach ( $routes as $route ) {
185 221 if ( isset( $route['route_module'] ) ) {
186 222 $boot_dependencies[] = array(
@@ -195,8 +231,23 @@
195 231 );
196 232 }
197 233 }
198 234
235 + /**
236 + * Filters the boot script-module dependencies for the
237 + * dashboard-wp-admin page.
238 + *
239 + * Surfaces extending this page can append entries to the boot
240 + * dependency list. Each entry is an array with 'import' (string
241 + * 'static' or 'dynamic') and 'id' (script-module handle) keys.
242 + *
243 + * @param array $boot_dependencies Boot dependencies for the page.
244 + */
245 + $boot_dependencies = apply_filters(
246 + 'dashboard-wp-admin_boot_dependencies',
247 + $boot_dependencies
248 + );
249 +
199 250 // Dummy script module to ensure dependencies are loaded
200 251 wp_register_script_module(
201 252 'dashboard-wp-admin',
202 253 $build_constants['build_url'] . 'pages/dashboard/loader.js',
@@ -219,30 +270,28 @@
219 270 ?>
220 271 <style>
221 272 /* Critical styles to prevent layout shifts - inlined for immediate application */
222 273
223 - /* Background colors */
224 274 #wpwrap {
225 - background: var(--wpds-color-fg-content-neutral, #1e1e1e);
226 275 overflow-y: auto;
227 276 }
228 - body {
277 + body.js {
229 278 background: #fff;
230 279 }
231 280
232 281 /* Reset wp-admin padding */
233 - #wpcontent {
282 + body.js #wpcontent {
234 283 padding-inline-start: 0;
235 284 }
236 - #wpbody-content {
285 + body.js #wpbody-content {
237 286 padding-bottom: 0;
238 287 }
239 288
240 289 /* Hide legacy admin elements */
241 - #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
290 + body.js #wpbody-content > div:not(#dashboard-wp-admin-app):not(#screen-meta) {
242 291 display: none;
243 292 }
244 - #wpfooter {
293 + body.js #wpfooter {
245 294 display: none;
246 295 }
247 296
248 297 /* Accessibility regions */
@@ -269,8 +318,22 @@
269 318 overflow-y: initial;
270 319 }
271 320 }
272 321 </style>
322 + <div class="wrap hide-if-js">
323 + <h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
324 + <?php
325 + wp_admin_notice(
326 + __( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
327 + array( 'type' => 'error' )
328 + );
329 + ?>
330 + </div>
331 + <?php
332 + // Core's pre-CSS Modules Boot layout uses this class for viewport sizing.
333 + // Remove it when the minimum supported WordPress version includes the Boot
334 + // changes from Gutenberg #81756.
335 + ?>
273 336 <div id="dashboard-wp-admin-app" class="boot-layout-container"></div>
274 337 <?php
275 338 }
276 339
@@ -275,5 +338,4 @@
275 338 }
276 339
277 340 // Hook the enqueue function to admin_enqueue_scripts
278 341 add_action( 'admin_enqueue_scripts', 'gutenberg_dashboard_wp_admin_enqueue_scripts' );
279 -