Commit ddee938d0cb for woocommerce
commit ddee938d0cb451f2d326c18d0f433662f9e8d448
Author: Tung Du <dinhtungdu@gmail.com>
Date: Wed Apr 1 10:42:23 2026 +0700
Fix Product Summary "Upgrade now" button not working in Site Editor (#63937)
* Fix Product Summary "Upgrade now" button not working in Site Editor
Use useRegistry() and useDispatch() hooks instead of bare select/dispatch
imports to ensure the correct data store registry is used. In the Site
Editor, the block editor store runs in a sub-registry, causing the
previous direct select()/dispatch() calls to operate on the wrong
registry and silently fail.
Also adds a null check for the block returned by getBlocksByClientId.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add changelog for Product Summary upgrade button fix
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Tung <tungbq@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/tangerine-1d1ffd0a b/plugins/woocommerce/changelog/tangerine-1d1ffd0a
new file mode 100644
index 00000000000..f5e2257caba
--- /dev/null
+++ b/plugins/woocommerce/changelog/tangerine-1d1ffd0a
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix Product Summary "Upgrade now (just this block)" button not working in the Site Editor.
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/upgrade.tsx b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/upgrade.tsx
index 920d23c4eb5..c53c08b1b51 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/upgrade.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/summary/upgrade.tsx
@@ -3,16 +3,13 @@
*/
import { __ } from '@wordpress/i18n';
import { addFilter } from '@wordpress/hooks';
-import {
- store as blockEditorStore,
- InspectorControls,
-} from '@wordpress/block-editor';
+import { InspectorControls } from '@wordpress/block-editor';
import {
createBlock,
type BlockEditProps,
type BlockInstance,
} from '@wordpress/blocks';
-import { select, dispatch } from '@wordpress/data';
+import { useDispatch, useRegistry } from '@wordpress/data';
import {
createInterpolateElement,
type ComponentType,
@@ -36,6 +33,9 @@ const isProductSummaryBlockVariation = ( props: BlockInstance ) => {
};
const UpgradeNotice = ( { clientId }: { clientId: string } ) => {
+ const registry = useRegistry();
+ const { replaceBlock } = useDispatch( 'core/block-editor' );
+
const notice = createInterpolateElement(
__(
"There's <strongText /> with important fixes and brand new features.",
@@ -53,12 +53,10 @@ const UpgradeNotice = ( { clientId }: { clientId: string } ) => {
const buttonLabel = __( 'Upgrade now (just this block)', 'woocommerce' );
const handleClick = () => {
- const blocks =
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore No types for this exist yet.
- select( blockEditorStore ).getBlocksByClientId( clientId );
+ const { getBlocksByClientId } = registry.select( 'core/block-editor' );
+ const blocks = getBlocksByClientId( clientId );
- if ( blocks.length ) {
+ if ( blocks?.length && blocks[ 0 ] ) {
const currentBlock = blocks[ 0 ];
const {
excerptLength,
@@ -71,12 +69,7 @@ const UpgradeNotice = ( { clientId }: { clientId: string } ) => {
'woocommerce/product-summary',
restAttributes
);
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore No types for this exist yet.
- dispatch( blockEditorStore ).replaceBlock(
- clientId,
- productSummaryBlock
- );
+ replaceBlock( clientId, productSummaryBlock );
}
};