Skip to content

Fixed visibility conditions change on duplicated blocks#2797

Open
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/2472
Open

Fixed visibility conditions change on duplicated blocks#2797
girishpanchal30 wants to merge 2 commits into
developmentfrom
bugfix/2472

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

Closes #2472

Summary

Added a helper function to clone the visibility conditions array to ensure that when a block with visibility conditions is duplicated, the new block has its own independent set of conditions. This prevents changes to the conditions in one block from affecting the other.

Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@girishpanchal30 girishpanchal30 requested a review from Copilot May 13, 2026 12:55
@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label May 13, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label May 13, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented May 13, 2026

Bundle Size Diff

Package Old Size New Size Diff
Animations 276.77 KB 276.77 KB 0 B (0.00%)
Blocks 1.55 MB 1.55 MB 108 B (0.01%)
CSS 105.9 KB 105.9 KB 0 B (0.00%)
Dashboard 204.08 KB 204.08 KB 0 B (0.00%)
Onboarding 165.94 KB 165.94 KB 0 B (0.00%)
Export Import 102.86 KB 102.86 KB 0 B (0.00%)
Pro 412.55 KB 412.66 KB 108 B (0.03%)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where duplicating a block with Visibility Conditions causes the original and duplicated blocks to share the same underlying nested conditions structure, so editing one updates the other.

Changes:

  • Added a deep-clone helper and switched condition mutation flows to clone before updating attributes.
  • Updated group/condition add/remove/edit handlers to use the new deep-clone approach.
Comments suppressed due to low confidence (1)

src/blocks/plugins/conditions/edit.js:433

  • This empty-group check is incorrect: 0 === otterConditions[index] compares an array to a number and will never be true. This means an empty condition group won’t be removed after deleting its last condition. Check the group length instead (e.g., otterConditions[index].length === 0).
		const otterConditions = deepClone( attributes.otterConditions );
		otterConditions[ index ].splice( key, 1 );

		if ( 0 === otterConditions[ index ]) {
			otterConditions.splice( index, 1 );

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/blocks/plugins/conditions/edit.js Outdated
Comment on lines 403 to 407
const addGroup = () => {
const otterConditions = [ ...( attributes.otterConditions || []) ];
const otterConditions = deepClone( attributes.otterConditions || [] );
const newGroupIndex = otterConditions.length; // Use the index of the new group
otterConditions.push([{}]);
setAttributes({ otterConditions });
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented May 13, 2026

Plugin build for 6c322e7 is ready 🛎️!

@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented May 13, 2026

E2E Tests

Playwright Test Status:

Performance Results serverResponse: {"q25":434.1,"q50":440.7,"q75":474.6,"cnt":10}, firstPaint: {"q25":406.5,"q50":441.3,"q75":506,"cnt":10}, domContentLoaded: {"q25":1649.1,"q50":1656.65,"q75":1669.4,"cnt":10}, loaded: {"q25":1649.6,"q50":1657,"q75":1669.9,"cnt":10}, firstContentfulPaint: {"q25":3452.6,"q50":3473.95,"q75":3494.4,"cnt":10}, firstBlock: {"q25":7054.1,"q50":7092.35,"q75":7189.7,"cnt":10}, type: {"q25":14.3,"q50":14.58,"q75":15.3,"cnt":10}, typeWithoutInspector: {"q25":12.37,"q50":12.76,"q75":13.6,"cnt":10}, typeWithTopToolbar: {"q25":18.73,"q50":19.01,"q75":19.44,"cnt":10}, typeContainer: {"q25":7.9,"q50":7.96,"q75":8.24,"cnt":10}, focus: {"q25":55.81,"q50":59.11,"q75":65.15,"cnt":10}, inserterOpen: {"q25":17.53,"q50":18.82,"q75":19.17,"cnt":10}, inserterSearch: {"q25":6.12,"q50":6.27,"q75":6.48,"cnt":10}, inserterHover: {"q25":2.66,"q50":2.81,"q75":3.03,"cnt":20}, loadPatterns: {"q25":1142.27,"q50":1180.87,"q75":1221.83,"cnt":10}, listViewOpen: {"q25":90.08,"q50":95.84,"q75":107.58,"cnt":10}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants