Fixed visibility conditions change on duplicated blocks#2797
Open
girishpanchal30 wants to merge 2 commits into
Open
Fixed visibility conditions change on duplicated blocks#2797girishpanchal30 wants to merge 2 commits into
girishpanchal30 wants to merge 2 commits into
Conversation
Contributor
Bundle Size Diff
|
There was a problem hiding this comment.
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 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 }); |
Contributor
|
Plugin build for 6c322e7 is ready 🛎️!
|
Contributor
E2E TestsPlaywright Test Status: Performance ResultsserverResponse: {"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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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