Make WordPress Core


Ignore:
Timestamp:
10/21/2025 11:30:43 AM (4 months ago)
Author:
luisherranz
Message:

Interactivity API: Support for loadOnClientNavigation.

Uses the wp_script_attributes filter to add a data-wp-router-options directive with a loadOnClientNavigation: true property for all the interactive blocks that are compatible with client-side navigation to let the Interactivity API router determine which modules it can safely load during client-side navigation.

Props luisherranz, westonruter.
Fixes #64122.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r60999 r61019  
    176176    $module_version      = isset( $module_asset['version'] ) ? $module_asset['version'] : $block_version;
    177177
    178     // Blocks using the Interactivity API are server-side rendered, so they are by design not in the critical rendering path and should be deprioritized.
     178    $supports_interactivity_true = isset( $metadata['supports']['interactivity'] ) && true === $metadata['supports']['interactivity'];
     179    $is_interactive              = $supports_interactivity_true || ( isset( $metadata['supports']['interactivity']['interactive'] ) && true === $metadata['supports']['interactivity']['interactive'] );
     180    $supports_client_navigation  = $supports_interactivity_true || ( isset( $metadata['supports']['interactivity']['clientNavigation'] ) && true === $metadata['supports']['interactivity']['clientNavigation'] );
     181
    179182    $args = array();
    180     if (
    181         ( isset( $metadata['supports']['interactivity'] ) && true === $metadata['supports']['interactivity'] ) ||
    182         ( isset( $metadata['supports']['interactivity']['interactive'] ) && true === $metadata['supports']['interactivity']['interactive'] )
    183     ) {
     183
     184    // Blocks using the Interactivity API are server-side rendered, so they are
     185    // by design not in the critical rendering path and should be deprioritized.
     186    if ( $is_interactive ) {
    184187        $args['fetchpriority'] = 'low';
    185188        $args['in_footer']     = true;
     189    }
     190
     191    // Blocks using the Interactivity API that support client-side navigation
     192    // must be marked as such in their script modules.
     193    if ( $is_interactive && $supports_client_navigation ) {
     194        wp_interactivity()->add_client_navigation_support_to_script_module( $module_id );
    186195    }
    187196
Note: See TracChangeset for help on using the changeset viewer.