Skip to content

Conversation

@shrivastavanolo
Copy link
Contributor

What?

Closes #67710

This PR updates the BlockSwitcher component to disable block transformations for reusable (synced) blocks. Template parts were already excluded; now reusable blocks will also hide transform options in the dropdown.

Why?

Currently, the BlockSwitcher allows transformations on reusable blocks. Transforming a reusable block can cause unexpected behavior, since all instances of the block are linked. Preventing transforms for these blocks ensures consistency across instances and prevents accidental data loss.

See #67710 (comment)

How?

  • Added an isReusable check in BlockSwitcherDropdownMenuContents.
  • Updated hasPossibleBlockTransformations to be false for reusable blocks

Testing Instructions

  1. Create a reusable block (or synced pattern).
  2. Select it in the editor and open the Block Switcher.
    • Before: Transform options are available.
    • After: Transform options are hidden/disabled.
  3. Select a normal block. Verify that the transform dropdown still works as expected.

Screenshots or screencast

Before

Screen.Recording.2025-09-15.at.5.25.00.PM.mov

After

Screen.Recording.2025-09-15.at.5.24.30.PM.mov

@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: shrivastavanolo <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: Rishit30G <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: richtabor <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Block Transforms Block transforms from one block to another labels Sep 15, 2025
@Mamaduka Mamaduka self-requested a review September 15, 2025 15:39
Comment on lines 111 to 116
const isReusable = isSingleBlock && isReusableBlock( blocks[ 0 ] );
const hasPossibleBlockTransformations =
!! possibleBlockTransformations.length && canRemove && ! isTemplate;
!! possibleBlockTransformations.length &&
canRemove &&
! isTemplate &&
! isReusable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's generalize the check and update the comment above; otherwise, it looks outdated.

Here's an example diff:

diff --git a/packages/block-editor/src/components/block-switcher/index.js b/packages/block-editor/src/components/block-switcher/index.js
index 8bd02e9357d..537d919c270 100644
--- a/packages/block-editor/src/components/block-switcher/index.js
+++ b/packages/block-editor/src/components/block-switcher/index.js
@@ -102,18 +102,16 @@ function BlockSwitcherDropdownMenuContents( {
 		selectForMultipleBlocks( transformedBlocks );
 	}
 	/**
-	 * The `isTemplate` check is a stopgap solution here.
+	 * The `isSynced` check is a stopgap solution here.
 	 * Ideally, the Transforms API should handle this
 	 * by allowing to exclude blocks from wildcard transformations.
 	 */
 	const isSingleBlock = blocks.length === 1;
-	const isTemplate = isSingleBlock && isTemplatePart( blocks[ 0 ] );
-	const isReusable = isSingleBlock && isReusableBlock( blocks[ 0 ] );
+	const isSynced =
+		isSingleBlock &&
+		( isTemplatePart( blocks[ 0 ] ) || isReusableBlock( blocks[ 0 ] ) );
 	const hasPossibleBlockTransformations =
-		!! possibleBlockTransformations.length &&
-		canRemove &&
-		! isTemplate &&
-		! isReusable;
+		!! possibleBlockTransformations.length && canRemove && ! isSynced;
 	const hasPossibleBlockVariationTransformations =
 		!! blockVariationTransformations?.length;
 	const hasPatternTransformation = !! patterns?.length && canRemove;

@shrivastavanolo shrivastavanolo force-pushed the fix/remove-transforms-for-synced-patterns branch from c76417a to 785399a Compare September 16, 2025 10:10
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @shrivastavanolo!

@Mamaduka Mamaduka merged commit bf38e96 into WordPress:trunk Sep 16, 2025
104 of 105 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.7 milestone Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Block Transforms Block transforms from one block to another [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extraneous transforms on synced patterns

3 participants