Make WordPress Core

Changeset 64438


Ignore:
Timestamp:
10/17/2026 04:45:30 PM (5 days ago)
Author:
jorgefilipecosta
Message:

Connectors: Preload the screen's REST API responses.

The Connectors screen requested the site settings, the OPTIONS response of the plugins endpoint, and the records of the AI plugin and of each connector's plugin only after its scripts loaded, which delayed its first render.
Adds the private _wp_connectors_preload_paths() callback to the wp_options_connectors_wp_admin_preload_paths filter, so these responses are embedded in the page. Only successful responses are preloaded, so the screen still requests the records of plugins that aren't installed.
The filter is applied by the page that the Gutenberg build generates, so the preloading takes effect once the pinned Gutenberg version includes ​https://github.com/WordPress/gutenberg/pull/77353.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11790 and ​https://github.com/WordPress/gutenberg/pull/77353.

Props westonruter, wildworks, jorgefilipecosta, mukesh27, apermo, ugyensupport, gziolo, justlevine, peterwilsoncc, ellatrix, cbravobernal.
Fixes #65215.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-connectors.php

    r63531 r64438  
    3333$parent_file = 'options-general.php';
    3434
     35/**
     36 * Preloads the REST API responses the Connectors UI fetches on mount.
     37 *
     38 * Without this, the page does a network round-trip for site settings,
     39 * plugin capability discovery, and each connector's plugin record after
     40 * the JS hydrates, which noticeably delays first paint.
     41 *
     42 * @since 7.2.0
     43 * @access private
     44 *
     45 * @param array<string|string[]> $preload_paths Paths already queued for preloading.
     46 * @return array<string|string[]> Paths with the Connectors-specific requests appended.
     47 *
     48 * @phpstan-param array<non-falsy-string|array{ non-falsy-string, 'GET'|'OPTIONS' }> $preload_paths
     49 * @phpstan-return array<non-falsy-string|array{ non-falsy-string, 'GET'|'OPTIONS' }>
     50 */
     51function _wp_connectors_preload_paths( array $preload_paths ): array {
     52        // getEntityRecord( 'root', 'site' ) in use-connector-plugin.ts / ai-plugin-callout.tsx.
     53        $preload_paths[] = '/wp/v2/settings';
     54
     55        // canUser( 'create', { kind: 'root', name: 'plugin' } ) in stage.tsx.
     56        $preload_paths[] = array( '/wp/v2/plugins', 'OPTIONS' );
     57
     58        // AiPluginCallout in routes/connectors-home/ai-plugin-callout.tsx queries this
     59        // hardcoded ID to check whether the WP AI plugin is installed/active.
     60        $preload_paths[] = '/wp/v2/plugins/ai/ai?context=edit';
     61
     62        // getEntityRecord( 'root', 'plugin', <basename> ) per connector in use-connector-plugin.ts.
     63        foreach ( wp_get_connectors() as $connector_data ) {
     64                if ( empty( $connector_data['plugin']['file'] ) ) {
     65                        continue;
     66                }
     67                // core-data's plugin entity uses the basename with `.php` stripped
     68                // as the record key (see routes/connectors-home/use-connector-plugin.ts).
     69                $basename        = preg_replace( '/\.php$/', '', plugin_basename( $connector_data['plugin']['file'] ) );
     70                $preload_paths[] = '/wp/v2/plugins/' . $basename . '?context=edit';
     71        }
     72
     73        return $preload_paths;
     74}
     75add_filter( 'wp_options_connectors_wp_admin_preload_paths', '_wp_connectors_preload_paths' );
     76
    3577require_once ABSPATH . 'wp-admin/admin-header.php';
    3678
Note: See TracChangeset for help on using the changeset viewer.