Commit d109fc5029 for woocommerce
commit d109fc5029eb256bd2e59af12b9b7915c4af1492
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date: Wed Sep 17 15:22:38 2025 +0200
Update Product Elements registration logic (#60971)
* Swap getCurrentPostId with getEditedPostSlug in register product blocks
* Add changelog
* Fix lint
* Bring back missing dependency
diff --git a/plugins/woocommerce/changelog/wooplug-5538-update-product-elements-registration-logic b/plugins/woocommerce/changelog/wooplug-5538-update-product-elements-registration-logic
new file mode 100644
index 0000000000..77690b4775
--- /dev/null
+++ b/plugins/woocommerce/changelog/wooplug-5538-update-product-elements-registration-logic
@@ -0,0 +1,4 @@
+Significance: patch
+Type: update
+
+Improve template slug recognition in mechanism registering product blocks. Assure compatibility with WordPress 6.9
diff --git a/plugins/woocommerce/client/blocks/assets/js/atomic/utils/register-product-block-type.ts b/plugins/woocommerce/client/blocks/assets/js/atomic/utils/register-product-block-type.ts
index 88fc9bcb58..bdfa85734a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/atomic/utils/register-product-block-type.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/atomic/utils/register-product-block-type.ts
@@ -12,7 +12,7 @@ import {
} from '@wordpress/blocks';
import { subscribe, select } from '@wordpress/data';
import { store as editorStore } from '@wordpress/editor';
-import { isNumber, isEmpty } from '@woocommerce/types';
+import { isEmpty } from '@woocommerce/types';
/**
* Settings for product block registration.
@@ -95,23 +95,6 @@ export class BlockRegistrationManager {
return BlockRegistrationManager.instance;
}
- /**
- * Parses a template ID from various possible formats.
- * Handles both string and number inputs due to Gutenberg changes.
- *
- * @param {string | number | undefined} templateId - The template ID to parse
- * @return {string | undefined} The parsed template ID
- */
- private parseTemplateId(
- templateId: string | number | undefined
- ): string | undefined {
- const parsedTemplateId = isNumber( templateId )
- ? undefined
- : templateId;
-
- return parsedTemplateId?.split( '//' )[ 1 ];
- }
-
/**
* Initializes subscriptions for template changes and block registration.
* Sets up listeners for both the site editor and post editor contexts.
@@ -159,14 +142,11 @@ export class BlockRegistrationManager {
// Unsubscribe from the main subscription since we've detected our context
unsubscribe();
- // @ts-expect-error getCurrentPostId is not typed
- const postId = editorSelectors.getCurrentPostId();
+ // @ts-expect-error getEditedPostSlug is not typed
+ const postSlug = editorSelectors.getEditedPostSlug();
// Set initial template ID
- this.currentTemplateId =
- typeof postId === 'string'
- ? this.parseTemplateId( postId )
- : undefined;
+ this.currentTemplateId = postSlug;
// Handle the initial template change
this.handleTemplateChange( undefined );
@@ -174,10 +154,9 @@ export class BlockRegistrationManager {
// Set up the template change listener
subscribe( () => {
const previousTemplateId = this.currentTemplateId;
- this.currentTemplateId = this.parseTemplateId(
- // @ts-expect-error getCurrentPostId is not typed
- editorSelectors.getCurrentPostId()
- );
+ this.currentTemplateId =
+ // @ts-expect-error getEditedPostSlug is not typed
+ editorSelectors.getEditedPostSlug();
if ( previousTemplateId !== this.currentTemplateId ) {
this.handleTemplateChange( previousTemplateId );