bobbingwide / bobbingwide

bobbingwide - Herb Miller's special repository
0 stars 0 forks source link

Fatal error: Uncaught TypeError: explode() in class-wp-dependencies.php:187 #84

Open bobbingwide opened 1 year ago

bobbingwide commented 1 year ago

Today, while updating the block docs for WordPress 6.1 I got a Fatal error when attempting to edit https://blocks.wp.a2z/block/no-results-core-query-no-results/

Gutenberg version: 14.1.1. Latest version of Gutenberg is 14.4.0


Warning: Array to string conversion in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php on line 76

Warning: Array to string conversion in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php on line 76

Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given in C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php:187

Stack trace:
#0 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php(187): explode('?', Array)
#1 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-styles.php(371): WP_Dependencies->all_deps(Array, false, false)
#2 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php(127): WP_Styles->all_deps(Array)
#3 C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php(83): WP_Dependencies->do_items(Array)
#4 C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php(109): gutenberg_resolve_assets()
#5 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php(310): {closure}(Array)
#6 C:\apache\htdocs\wp-a2z\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#7 C:\apache\htdocs\wp-a2z\wp-includes\block-editor.php(539): apply_filters('block_editor_se...', Array, Object(WP_Block_Editor_Context))
#8 C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php(284): get_block_editor_settings(Array, Object(WP_Block_Editor_Context))
#9 C:\apache\htdocs\wp-a2z\wp-admin\post.php(187): require('C:\\apache\\htdoc...')
#10 {main}
  thrown in <b>C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php</b> on line <b>187</b><br />
bobbingwide commented 1 year ago

Updating to Gutenberg 14.4.0 seemed to resolve the issue. It still crashed with: 14.3.1, 14.3.0 and 14.2.0 Which might be a bit of a shame since WordPress 6.1 includes Gutenberg 14.1

bobbingwide commented 1 year ago

I retested after updating to WordPress 6.1-RC5. I still get the errors with Gutenberg 14.3.1 and earlier

Gutenberg version Result
14.4.0 works
14.3.1 fails as above
14.3.0 fails as above
14.2.0 fails as above
14.1.1 fails as above
bobbingwide commented 1 year ago

The stack trace for the first warning

C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(286:2) bw_trace_error_handler(1) 219 24 2022-10-31T21:19:52+00:00 2.758449 0.023853 cf=block_editor_settings_all 76280 168 10266 18874368/18874368 512M F=1303 err Array

[0] => (integer) 2
[1] => (string) "Warning: Array to string conversion"
[2] => (string) "C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php"
[3] => (integer) 76
0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:293 0
2. bw_trace_error_handler(2,Array to string conversion,C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php,76) C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:0 4
3. array_unique(array) C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php:76 1
4. gutenberg_resolve_assets C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php:109 0
5. {closure}(array) C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php:310 1
6. apply_filters(array,array) C:\apache\htdocs\wp-a2z\wp-includes\plugin.php:205 2
7. apply_filters(block_editor_settings_all,array,object) C:\apache\htdocs\wp-a2z\wp-includes\block-editor.php:539 3
8. get_block_editor_settings(array,object) C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php:284 2
9. require(C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php) C:\apache\htdocs\wp-a2z\wp-admin\post.php:187 1

is most likely related to the fact that the style_handles array is not flat, with two entries which are themselves arrays.

  [151] => Array

        [0] => (string) "wp-block-post-comments-form"
        [1] => (string) "wp-block-buttons"
        [2] => (string) "wp-block-button"

and

 [228] => Array

        [0] => (string) "wp-block-post-comments"
        [1] => (string) "wp-block-buttons"
        [2] => (string) "wp-block-button"

In WP 6.1-RC5 if _wp_get_iframed_editor_assets() exists then the filter function for block_editor_settings_all just returns the $settings.

In WP 6.1-RC3 it called gutenberg_resolve_assets(), which produced the Warnings.

I believe I've found the original issue. https://github.com/WordPress/gutenberg/issues/45301

bobbingwide commented 1 year ago

_wp_get_iframed_editor_assets() uses different logic to gutenberg_resolve_assets() to build $style_handles and $script_handles

foreach ( $block_registry->get_all_registered() as $block_type ) {
        $style_handles = array_merge(
            $style_handles,
            $block_type->style_handles,
            $block_type->editor_style_handles
        );

        $script_handles = array_merge(
            $script_handles,
            $block_type->script_handles
        );
    }

compared with the logic in gutenberg_resolve_assets(), which doesn't use array_merge().

foreach ( $block_registry->get_all_registered() as $block_type ) {
        if ( ! empty( $block_type->style ) ) {
            $style_handles[] = $block_type->style;
        }

        if ( ! empty( $block_type->editor_style ) ) {
            $style_handles[] = $block_type->editor_style;
        }

        if ( ! empty( $block_type->script ) ) {
            $script_handles[] = $block_type->script;
        }
    }