Commit fd073089293 for woocommerce
commit fd073089293f01001c4758dd69c9d00d8cff135f
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date: Mon Aug 3 12:23:46 2026 +0200
Avoid dirty state on templates using Classic Template block (#67093)
* Fix Classic Template automatic updates dirtying the editor
* Add changelog entry for Classic Template editor fix
diff --git a/plugins/woocommerce/changelog/codex-prevent-classic-template-save-prompt b/plugins/woocommerce/changelog/codex-prevent-classic-template-save-prompt
new file mode 100644
index 00000000000..1205812d7b7
--- /dev/null
+++ b/plugins/woocommerce/changelog/codex-prevent-classic-template-save-prompt
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent the Site Editor from showing unsaved changes when opening classic WooCommerce templates.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/index.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/index.tsx
index 954979c4d19..11d98a6f77a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/classic-template/index.tsx
@@ -181,6 +181,8 @@ const Edit = ( {
setAttributes,
}: BlockEditProps< Attributes > ) => {
const blockProps = useBlockProps();
+ const { __unstableMarkNextChangeAsNotPersistent } =
+ useDispatch( blockEditorStore );
const { currentPostId } = useSelect( ( sel ) => {
return {
currentPostId: sel( CORE_EDITOR_STORE )?.getCurrentPostId?.() ?? 0,
@@ -202,14 +204,27 @@ const Edit = ( {
const templatePlaceholder = templateDetails?.placeholder ?? 'fallback';
const templateType = templateDetails?.type ?? 'fallback';
- useEffect(
- () =>
+ useEffect( () => {
+ const nextTemplate = templateSlug ?? attributes.template;
+ const nextAlign = attributes.align ?? 'wide';
+
+ if (
+ nextTemplate !== attributes.template ||
+ nextAlign !== attributes.align
+ ) {
+ __unstableMarkNextChangeAsNotPersistent();
setAttributes( {
- template: templateSlug ?? attributes.template,
- align: attributes.align ?? 'wide',
- } ),
- [ attributes.align, attributes.template, setAttributes, templateSlug ]
- );
+ template: nextTemplate,
+ align: nextAlign,
+ } );
+ }
+ }, [
+ attributes.align,
+ attributes.template,
+ setAttributes,
+ templateSlug,
+ __unstableMarkNextChangeAsNotPersistent,
+ ] );
const { getDescription, getSkeleton, blockifyConfig } =
conversionConfig[ templateType ];