Pattern Editing: Fix nested patterns/sections#75772
Conversation
…out and additional Edit pattern step
|
Size Change: -54 B (0%) Total Size: 6.84 MB
ℹ️ View Unchanged
|
| if ( | ||
| state.editedContentOnlySection && | ||
| ( isWithinEditedContentOnlySection( state, clientId ) || | ||
| clientId === state.editedContentOnlySection ) | ||
| ) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Looking at isWithinEditedContentOnlySection(), it already checks for state.editedContentOnlySection and returns true when clientId === editedContentOnlySection, could this be:
if ( isWithinEditedContentOnlySection( state, clientId ) ) {
return false;
}Or am I missing a subtlety?
Also, just checking if the order matters here. Previously a core/block always returned true from isSectionBlock regardless of editing context.
|
According to #75762 :
This doesn't match what I see in trunk: edit mode on the parent doesn't unlock editing in inner patterns:
(in the example I'm editing the parent Group pattern but the Cover pattern isn't in editable mode)
This PR fixes that, but it still shows the "Edit pattern" in the nested pattern when the parent isn't being edited. The problem with that is clicking to edit only the nested pattern doesn't work:
So we should either remove it altogether, or if we want it to be possible to edit only a nested pattern, there's a bigger bug to fix here 😅 I'm inclined towards removing it altogether, because currently we only get to see the toolbar in a nested pattern if the pattern container happens to be a content block (such as the Cover I used in the examples). Nesting a pattern with a Group container for instance means the toolbar is inaccessible unless we edit the parent. |
Yep, seems like there are bugs with synced patterns. They're a little different to other patterns as the user has to explicitly use 'Enable overrides' to make child block editable when a synced pattern is inserted. That should be the case everywhere except for when using 'Edit original'. |
@tellthemachines I think this was happening when the top level block in the nested pattern is also a content block (like cover) as that makes the nested pattern selectable. I've pushed a commit that should fix it. |
It looks correct. In List View just the non-content blocks are removed, but nesting remains. |
| const { clientId, name: blockName } = block; | ||
|
|
||
| // Set the edited section and all blocks within it to 'default', so that all changes can be made. | ||
| if ( state.editedContentOnlySection ) { | ||
| // If this is the edited section, use the default mode. | ||
| if ( state.editedContentOnlySection === clientId ) { | ||
| derivedBlockEditingModes.set( clientId, 'default' ); | ||
| return; | ||
| } | ||
|
|
||
| // If the block is within the edited section also use the default mode. | ||
| const parentTempEditedClientId = findParentInClientIdsList( | ||
| state, | ||
| clientId, | ||
| [ state.editedContentOnlySection ] | ||
| ); | ||
| if ( parentTempEditedClientId ) { | ||
| derivedBlockEditingModes.set( clientId, 'default' ); | ||
| return; | ||
| } | ||
|
|
||
| // Disable blocks that are outside of the edited section. |
There was a problem hiding this comment.
Part 1 of the fix for synced patterns. I've moved this code for handling the block editing modes of edited content only sections lower down in the function so that it has a lower precedence, synced pattern will have a higher precedence so will retain their block editing modes when nested in an unsynced pattern that's being edited.
| // from the instance, the user has to edit the pattern source, | ||
| // so return 'disabled'. | ||
| derivedBlockEditingModes.set( clientId, 'disabled' ); | ||
| return; |
There was a problem hiding this comment.
Part 2 of the fix for synced patterns, there was no return statement here, so the execution would continue and run the block editing mode logic for unsynced patterns, overriding whatever was set for synced patterns. 🤦♂️
|
Flaky tests detected in ece53b8. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22293169467
|
ece53b8 to
0e77d2a
Compare
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
This should be ready for review now. I'll split the synced pattern fixes into a separate PR. |
There was a problem hiding this comment.
100% optional: can be here or in a follow up. Just noticed it was hasContentOnlyTempateLock and note hasContentOnlyTemplateLock while testing.
| // The walk encounters middle-pattern (the edited section) before | ||
| // reaching outer-pattern, so it returns undefined early — outer-pattern | ||
| // above the edited section is not returned. | ||
| expect( | ||
| getParentSectionBlock( state, 'deep-block' ) | ||
| ).toBeUndefined(); |
There was a problem hiding this comment.
Reading the comment here, is it while loop (the walk) returning undefined or what was the old behaviour?
There was a problem hiding this comment.
I'll remove this test, I think it's basically not possibly now to have a nested (middle) pattern be the edited section.
* When editing a pattern allow editing for all nested patterns too without and additional Edit pattern step * Add tests * Simplify early return * Consider nested sections in isSectionBlock * Refactor to avoid recursive calls between isSectionBlock and getParentSectionBlock * Fix variable naming * Remove not needed test ---- Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: d910f28 |
* When editing a pattern allow editing for all nested patterns too without and additional Edit pattern step * Add tests * Simplify early return * Consider nested sections in isSectionBlock * Refactor to avoid recursive calls between isSectionBlock and getParentSectionBlock * Fix variable naming * Remove not needed test ---- Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
|
I just cherry-picked this PR to the release/22.6 branch to get it included in the next release: ec5a434 |
CI run: #11059. See #64595. --- I've included a log of the Gutenberg changes with the following command: git log --reverse --format="- %s" 23b566c72e9c4a36219ef5d6e62890f05551f6cb..022d8dd3d461f91b15c1f0410649d3ebb027207f | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy - Pattern Editing: Fix nested patterns/sections (WordPress/gutenberg#75772) - QuickEdit: rename status label and remove extra labels in popup (WordPress/gutenberg#75824) - Fix block editing modes not recomputing when isolated editor value changes (WordPress/gutenberg#75821) - Synced patterns: Fix block editing mode of synced pattern content when nested in an unsynced pattern (WordPress/gutenberg#75818) - Block Support: Fix custom CSS not saved when style schema is not defined (WordPress/gutenberg#75797) - Gallery: Fixes keyboard focus escaping the lightbox overlay when navigating a gallery with Tab/Shift+Tab. (WordPress/gutenberg#75852) - Navigation Overlay Close: Set Close as default text, rather than using a placeholder (WordPress/gutenberg#75692) - RTC: Fix entity save call / initial persistence. (WordPress/gutenberg#75841) - Real-time collaboration: Improve collaboration within the same rich text (WordPress/gutenberg#75703) - Client Side Media: Add device/browser capability detection (WordPress/gutenberg#75863) - Navigation editing: simplify edit/view buttons (WordPress/gutenberg#75819) - Add core/icon block to theme.json schema (WordPress/gutenberg#75813) - Fix error when undoing newly added pattern (WordPress/gutenberg#75850) - Page List Item: Replace RawHTML with dangerouslySetInnerHTML for label and title (WordPress/gutenberg#75890) - REST API: Make filter_wp_unique_filename() static to match core, plus avoid duplicate routes (WordPress/gutenberg#75782) - RichText: useAnchor: Fix TypeError in virtual element (WordPress/gutenberg#75900) - DataViews: Remove menu divider again. (WordPress/gutenberg#75908) - Theme: Add build plugins to inject design token fallbacks (WordPress/gutenberg#75901) - Theme: Remove global stylesheet (WordPress/gutenberg#75879) - Real-time collaboration: Remove ghost awareness state explicitly when refreshing (WordPress/gutenberg#75883) - Real-time collaboration: Expand mergeCrdtBlocks() automated testing (WordPress/gutenberg#75923) - Fix client-side media file naming (WordPress/gutenberg#75817) - Add: Connectors screen (WordPress/gutenberg#75833) - Merge document meta into state map (WordPress/gutenberg#75830) - Move WordPress meta key from sync package to core-data (WordPress/gutenberg#75846) - Bugfix: Fix casing of getPersistedCRDTDoc (WordPress/gutenberg#75922) - Add debug logging to SyncManager (WordPress/gutenberg#75924) - DataForm: fix label colors (WordPress/gutenberg#75730) - DataViews: minimize padding for primary action buttons (WordPress/gutenberg#75721) (WordPress/gutenberg#75947) - Connectors: Add `_ai_` prefix to connector setting names and fix naming inconsistencies (WordPress/gutenberg#75948) - Connectors: Unhook Core callbacks in Gutenberg coexistence (WordPress/gutenberg#75935) - Unsynced patterns: Rename 'Disconnect pattern' to 'Detach pattern' in context menu (WordPress/gutenberg#75807) - Editor: Remove View dropdown and pinned items from revisions header (WordPress/gutenberg#75951) - Fix: Template revisions infinite spinner (WordPress/gutenberg#75953) - Backport: Avoid flickering while refreshing (WordPress/gutenberg#74572) (WordPress/gutenberg#75952) - Add wp_ prefix to real time collaberation option. (WordPress/gutenberg#75837) git-svn-id: https://develop.svn.wordpress.org/trunk@61750 602fd350-edb4-49c9-b593-d223f7449a82
CI run: WordPress/wordpress-develop#11059. See #64595. --- I've included a log of the Gutenberg changes with the following command: git log --reverse --format="- %s" 23b566c72e9c4a36219ef5d6e62890f05551f6cb..022d8dd3d461f91b15c1f0410649d3ebb027207f | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy - Pattern Editing: Fix nested patterns/sections (WordPress/gutenberg#75772) - QuickEdit: rename status label and remove extra labels in popup (WordPress/gutenberg#75824) - Fix block editing modes not recomputing when isolated editor value changes (WordPress/gutenberg#75821) - Synced patterns: Fix block editing mode of synced pattern content when nested in an unsynced pattern (WordPress/gutenberg#75818) - Block Support: Fix custom CSS not saved when style schema is not defined (WordPress/gutenberg#75797) - Gallery: Fixes keyboard focus escaping the lightbox overlay when navigating a gallery with Tab/Shift+Tab. (WordPress/gutenberg#75852) - Navigation Overlay Close: Set Close as default text, rather than using a placeholder (WordPress/gutenberg#75692) - RTC: Fix entity save call / initial persistence. (WordPress/gutenberg#75841) - Real-time collaboration: Improve collaboration within the same rich text (WordPress/gutenberg#75703) - Client Side Media: Add device/browser capability detection (WordPress/gutenberg#75863) - Navigation editing: simplify edit/view buttons (WordPress/gutenberg#75819) - Add core/icon block to theme.json schema (WordPress/gutenberg#75813) - Fix error when undoing newly added pattern (WordPress/gutenberg#75850) - Page List Item: Replace RawHTML with dangerouslySetInnerHTML for label and title (WordPress/gutenberg#75890) - REST API: Make filter_wp_unique_filename() static to match core, plus avoid duplicate routes (WordPress/gutenberg#75782) - RichText: useAnchor: Fix TypeError in virtual element (WordPress/gutenberg#75900) - DataViews: Remove menu divider again. (WordPress/gutenberg#75908) - Theme: Add build plugins to inject design token fallbacks (WordPress/gutenberg#75901) - Theme: Remove global stylesheet (WordPress/gutenberg#75879) - Real-time collaboration: Remove ghost awareness state explicitly when refreshing (WordPress/gutenberg#75883) - Real-time collaboration: Expand mergeCrdtBlocks() automated testing (WordPress/gutenberg#75923) - Fix client-side media file naming (WordPress/gutenberg#75817) - Add: Connectors screen (WordPress/gutenberg#75833) - Merge document meta into state map (WordPress/gutenberg#75830) - Move WordPress meta key from sync package to core-data (WordPress/gutenberg#75846) - Bugfix: Fix casing of getPersistedCRDTDoc (WordPress/gutenberg#75922) - Add debug logging to SyncManager (WordPress/gutenberg#75924) - DataForm: fix label colors (WordPress/gutenberg#75730) - DataViews: minimize padding for primary action buttons (WordPress/gutenberg#75721) (WordPress/gutenberg#75947) - Connectors: Add `_ai_` prefix to connector setting names and fix naming inconsistencies (WordPress/gutenberg#75948) - Connectors: Unhook Core callbacks in Gutenberg coexistence (WordPress/gutenberg#75935) - Unsynced patterns: Rename 'Disconnect pattern' to 'Detach pattern' in context menu (WordPress/gutenberg#75807) - Editor: Remove View dropdown and pinned items from revisions header (WordPress/gutenberg#75951) - Fix: Template revisions infinite spinner (WordPress/gutenberg#75953) - Backport: Avoid flickering while refreshing (WordPress/gutenberg#74572) (WordPress/gutenberg#75952) - Add wp_ prefix to real time collaberation option. (WordPress/gutenberg#75837) Built from https://develop.svn.wordpress.org/trunk@61750 git-svn-id: http://core.svn.wordpress.org/trunk@61056 1a063a9b-81f0-0310-95a4-ce76da25c4cd






What?
Alternative to #75762
Fixes some quirks for patterns that are nested inside other patterns.
Fixes the following issues:
Problem: A nested unsynced pattern that has a content block as its root block had its own 'Edit pattern' button on its toolbar. If the user opens the block inspector, that also shows an 'Edit pattern' button, but that one's for the parent pattern, which can cause confusion.
Solution: Only the parent pattern should have an 'Edit pattern' button, when clicked it initiates editing for all nested unsynced patterns.
Problem: When 'Edit pattern' is clicked, nested patterns were not fully editable and still showed an 'Edit pattern' button.
Solution: Similar to above, nested unsynced patterns are entirely managed by their parent pattern.
Code changes
isSectionBlocknow returnsfalseif the current clientId has a parent section or an edited parent section.getParentSectionBlockalso returnsundefinedif there's a parent edited section.Testing Instructions
Screenshots or screencast
Before
Nested unsynced pattern has its own 'Edit pattern' toolbar button, and when clicking 'Edit pattern' on the parent, the nested patterns inner blocks are still not fully editable
Kapture.2026-02-23.at.14.08.26.mp4
After
Nested unsynced patterns are now managed by their parent. They have no 'Edit pattern' button of their own. When 'Edit pattern' is clicked on the parent, the nested pattern is fully editable.
Kapture.2026-02-23.at.14.11.37.mp4