Make WordPress Core

Changeset 56744


Ignore:
Timestamp:
09/29/2023 01:13:54 PM (14 months ago)
Author:
spacedmonkey
Message:

Editor: Avoid Deferring Loading for Empty Block Script URI

In the context of register_block_script_handle, the get_block_asset_url function may return false when an empty string is provided as the input. This behavior is intended to prevent the generation of invalid URLs. However, when the script loading strategy is set to "defer" while passing false, it triggers a "doing it wrong" message.

This situation becomes problematic, especially for scenarios where the scripts haven't been built yet. In such cases, the realpath call returns an empty string because the file doesn't exist. To address this issue, we now perform a simple check to ensure that the script URI is not empty before applying the "defer" loading strategy. This adjustment prevents unnecessary deferral of loading for scripts with empty URIs.

Follow on from [56683] and [56033].

Props kebbet, mukesh27, swissspidy, westonruter, spacedmonkey.
Fixes #59475

File:
1 edited

Legend:

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

    r56709 r56744  
    182182
    183183    $script_args = array();
    184     if ( 'viewScript' === $field_name ) {
     184    if ( 'viewScript' === $field_name && $script_uri ) {
    185185        $script_args['strategy'] = 'defer';
    186186    }
Note: See TracChangeset for help on using the changeset viewer.