contentOnly template lock: Fix block insertion and removal rules#77119
contentOnly template lock: Fix block insertion and removal rules#77119
Conversation
…terBlock The template lock guard in these actions was redundant with two other layers: the UI layer (canInsertBlockType hides the menu items) and the dispatch layer (insertBlocks filters blocks through canInsertBlockType). The removed check was also the least precise of the three, causing insert before/after to be silently blocked in contentOnly mode.
Test that Add before, Add after, Duplicate, and Delete actually work (or are correctly blocked) for blocks inside a contentOnly group. These tests exercise the actions end-to-end rather than just checking menu item visibility.
|
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. |
|
Size Change: -6 B (0%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 2706de5. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24117362878
|
There was a problem hiding this comment.
This is testing well for me!
Great find that canInsertBlockType already does getTemplateLock checks
I compared to trunk:
✅ Fixes the bug reported in #76881
✅ Last remaining block cannot be deleted - i also checked with other blocks. List items can be completely deleted, but this is okay since the list block itself cannot
✅ I checked unsynced patterns - this PR makes things more consistent between templateLock: contentOnly and unsynced patters in terms of inserting and gating deletion on the last item
✅ Preserves "templateLock":"all" behaviour
) * Fix insert before/after being disallowed in templateLock: contentOnly * Fix inconsistent block removal * Remove redundant template lock checks from insertBeforeBlock/insertAfterBlock The template lock guard in these actions was redundant with two other layers: the UI layer (canInsertBlockType hides the menu items) and the dispatch layer (insertBlocks filters blocks through canInsertBlockType). The removed check was also the least precise of the three, causing insert before/after to be silently blocked in contentOnly mode. * Add e2e tests for block operations in contentOnly mode Test that Add before, Add after, Duplicate, and Delete actually work (or are correctly blocked) for blocks inside a contentOnly group. These tests exercise the actions end-to-end rather than just checking menu item visibility. ---- Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: mrleemon <leemon@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: 42690fe |
What?
Closes #76881
Fixes two bugs with
templateLock: "contentOnly"and adds e2e tests covering block operations in content-only mode.Why?
When using
templateLock: "contentOnly"on a Group block, "Add before" and "Add after" options were visible in the block options menu but did nothing when clicked.Additionally, the block removal logic had an inconsistency where the last default block (paragraph) in a content-only section could sometimes be removed when it shouldn't be.
How?
Fix 1: Remove redundant template lock checks from
insertBeforeBlock/insertAfterBlockThe
insertBeforeBlockandinsertAfterBlockactions had their own template lock guard that bailed out for any truthytemplateLock, includingcontentOnly. This check prevented Add before / after from working as expected. The fix is to remove it entirely since there are already separate checks againstcanInsertBlockTypein the codebase prior to inserting blocks.Fix 2: Fix inconsistent block removal in
canRemoveBlockThe
canRemoveBlockselector had a bug in the content-only section. When checking whether a default block (paragraph) could be removed, the code had anelsebranch that was unreachable (the enclosingifalready ensuredblockName === defaultBlockName). This caused thereturn falsefor single-default-block cases to be skipped, falling through to a less restrictive check. The fix restructures the conditionals so that when only one default block remains, removal is correctly disallowed.E2e tests
Adds new e2e tests.
Testing Instructions
Use of AI Tools
OpenCode (Claude) was used to assist with writing the e2e tests and the PR description. All changes were reviewed and validated by the author.