Widgets: Stop loading wp-editor and the Block Directory assets on the widgets screen.

When using the text widget, a `wp.editor.initialize is not a function` notice is encountered. This happens when `wp-editor` is loaded as a dependency, which assigns `wp.oldEditor = wp.editor` and then redefines `wp.editor`.

`wp-editor` is only used for the Classic block, which is not supported in the new widgets editor. [51198-51199] updated `@wordpress/block-library` to remove `wp-editor` as a dependency, but it’s still listed as a dependency of the `wp-block-directory` script handle.

Since the Block directory is not supported within the widgets editor, the related assets can safely be blocked from enqueueing.

Props noisysocks, gziolo, Mamaduka, mkaz.
Fixes . See .

git-svn-id: https://develop.svn.wordpress.org/trunk@51202 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2021-06-22 16:54:50 +00:00
parent 4351b2ca31
commit 7368e86994

@ -29,6 +29,11 @@ $editor_settings = get_block_editor_settings(
$block_editor_context
);
// The widgets editor does not support the Block Directory, so don't load any of
// its assets. This also prevents 'wp-editor' from being enqueued which we
// cannot load in the widgets screen because many widget scripts rely on `wp.editor`.
remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
wp_add_inline_script(
'wp-edit-widgets',
sprintf(
@ -67,7 +72,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php';
do_action( 'widgets_admin_page' );
?>
<div id="widgets-editor" class="blocks-widgets-container"></div>
<div id="widgets-editor" class="blocks-widgets-container"></div>
<?php
/** This action is documented in wp-admin/widgets-form.php */