Commit 479b27c81c7 for woocommerce
commit 479b27c81c771e9739c6a5f11de07e85d4299e3c
Author: Luigi Teschio <gigitux@gmail.com>
Date: Wed Jul 29 17:51:15 2026 +0200
Fix widget editor block initialization errors (#67112)
* Fix widget editor block initialization errors
* Add changelog entry for widget editor fix
* Improve widget editor dependency comment
* Explain missing editor store guard
* Clarify widget editor script conflict
* improve comment
* clean up code
diff --git a/plugins/woocommerce/changelog/fix-47831-widget-editor-wp-editor-dependency b/plugins/woocommerce/changelog/fix-47831-widget-editor-wp-editor-dependency
new file mode 100644
index 00000000000..b786c59813f
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-47831-widget-editor-wp-editor-dependency
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent block initialization errors in the classic widget editor.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/plugins/index.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/plugins/index.tsx
index 768f7f10ecd..e56a75e4d69 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/plugins/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/plugins/index.tsx
@@ -44,12 +44,20 @@ function ProductTypeSwitcher() {
export default function ProductTypeSelectorPlugin() {
const { slug, type } = useSelect( ( select ) => {
- const { slug: currentPostSlug, type: currentPostType } = select(
- 'core/editor'
- ).getCurrentPost< {
- slug: string;
- type: string;
- } >();
+ const editorStore = select( 'core/editor' );
+ // The widget editor does not load wp-editor, so the core/editor store may be unavailable.
+ if ( ! editorStore ) {
+ return {
+ slug: '',
+ type: '',
+ };
+ }
+
+ const { slug: currentPostSlug, type: currentPostType } =
+ editorStore.getCurrentPost< {
+ slug: string;
+ type: string;
+ } >();
return {
slug: currentPostSlug,
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
index 43057813918..082bc3a0fe0 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
@@ -230,14 +230,24 @@ abstract class AbstractBlock {
return;
}
- $wp_scripts->registered[ $handle ]->deps = array_values(
- array_unique(
- array_merge(
- $wp_scripts->registered[ $handle ]->deps,
- $dependencies
- )
+ $script_dependencies = array_unique(
+ array_merge(
+ $wp_scripts->registered[ $handle ]->deps,
+ $dependencies
)
);
+
+ // For performance, the unified block library combines all block editor assets, so its dependencies include
+ // wp-editor even though blocks available in the widget editor do not use it. WordPress treats loading
+ // wp-editor alongside the block-based widget editor as incorrect usage, so remove it only on this screen.
+ if ( 'wc-block-library' === $handle && function_exists( 'get_current_screen' ) ) {
+ $screen = get_current_screen();
+ if ( $screen && 'widgets' === $screen->base ) {
+ $script_dependencies = array_diff( $script_dependencies, array( 'wp-editor' ) );
+ }
+ }
+
+ $wp_scripts->registered[ $handle ]->deps = array_values( $script_dependencies );
}
/**
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/widget-area/widget-area.classic_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/widget-area/widget-area.classic_theme.spec.ts
new file mode 100644
index 00000000000..f2c79f120ca
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/widget-area/widget-area.classic_theme.spec.ts
@@ -0,0 +1,23 @@
+/**
+ * External dependencies
+ */
+import { test, expect, CLASSIC_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+test.describe( 'Merchant → Widget area', () => {
+ test.beforeEach( async ( { requestUtils } ) => {
+ await requestUtils.activateTheme( CLASSIC_THEME_SLUG );
+ } );
+
+ test( 'does not render an error notice', async ( { admin, page } ) => {
+ await admin.visitWidgetEditor();
+
+ // Verify the wp-editor script wasn't loaded.
+ // See: https://github.com/woocommerce/woocommerce/issues/47831
+ await expect( page.locator( '#wp-editor-js' ) ).toHaveCount( 0 );
+
+ // Verify that no error notice is rendered in the widget editor.
+ await expect(
+ page.locator( '.components-notice.is-error' )
+ ).toHaveCount( 0 );
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/admin/index.ts b/plugins/woocommerce/tests/e2e/utils/blocks/admin/index.ts
index d4dbde2d4b9..5d407882de4 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/admin/index.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/admin/index.ts
@@ -35,10 +35,6 @@ export class Admin extends CoreAdmin {
.getByRole( 'dialog', { name: 'Welcome to block Widgets' } )
.getByRole( 'button', { name: 'Close' } );
- // Verify the wp-editor script wasn't loaded.
- // See: https://github.com/woocommerce/woocommerce/issues/47831
- await expect( this.page.locator( '#wp-editor-js' ) ).toHaveCount( 0 );
-
// The welcome guide only shows when it hasn't been dismissed before, so
// wait for it briefly and close it only when it actually appears.
const guideAppeared = await closeWelcomeGuide