Skip to content

fix: only apply template on first insert so unlocked changes persist …#3692

Open
Arukuen wants to merge 1 commit intodevelopfrom
fix/3566/3677-template-unlock
Open

fix: only apply template on first insert so unlocked changes persist …#3692
Arukuen wants to merge 1 commit intodevelopfrom
fix/3566/3677-template-unlock

Conversation

@Arukuen
Copy link
Contributor

@Arukuen Arukuen commented Mar 19, 2026

…on referesh

fixes #3677
fixes #3556

Variation change after inserting the block still works.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where block templates were being reapplied to blocks that already contained content. Templates now only appear when blocks are empty, preventing unwanted content overrides in blockquote, expand, price, and video popup blocks.

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Four block edit components (blockquote, expand, price, video-popup) now conditionally apply InnerBlocks templates—passing the template only when no inner blocks exist, preventing template reapplication when blocks have been deleted.

Changes

Cohort / File(s) Summary
Conditional InnerBlocks Template Application
src/block/blockquote/edit.js, src/block/expand/edit.js, src/block/price/edit.js, src/block/video-popup/edit.js
Each component now imports useSelect from @wordpress/data and derives hasInnerBlocks from the block editor store. The InnerBlocks template prop is conditionally set—passing TEMPLATE only when hasInnerBlocks is false; otherwise passes undefined. This prevents the template from being re-inserted when inner blocks have been deleted.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A template once stood tall and true,
But deletions would undo, then undo anew!
Now conditions guard the block with care,
When inner blocks vanish into thin air—
They stay gone, as they should be,
No ghostly returns for you or me! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: applying template only on first insert to preserve unlocked changes, which directly addresses the PR's core objective.
Linked Issues check ✅ Passed The code changes directly address both linked issues by preventing template reapplication on subsequent renders, ensuring deleted unlocked inner blocks persist after page refresh.
Out of Scope Changes check ✅ Passed All changes are focused and in-scope: they apply the same pattern (conditional template application based on hasInnerBlocks) to blockquote, expand, price, and video-popup blocks consistently.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3566/3677-template-unlock
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

🤖 Pull request artifacts

file commit
pr3692-stackable-3692-merge.zip 1817b7f

github-actions bot added a commit that referenced this pull request Mar 19, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/block/blockquote/edit.js (1)

62-67: Consider extracting hasInnerBlocks selector into a shared hook.

This exact selector pattern is now duplicated in multiple block edit files. A small shared hook (e.g., useHasInnerBlocks(clientId)) would reduce drift and make future template-init updates safer.

♻️ Proposed refactor sketch
+// e.g. src/block/common/hooks/use-has-inner-blocks.js
+import { useSelect } from '@wordpress/data'
+
+export const useHasInnerBlocks = clientId => {
+	return useSelect( select => {
+		const { getBlockOrder } = select( 'core/block-editor' )
+		return getBlockOrder( clientId ).length > 0
+	}, [ clientId ] )
+}
-import { useSelect } from '@wordpress/data'
+import { useHasInnerBlocks } from '../common/hooks/use-has-inner-blocks'
...
-const { hasInnerBlocks } = useSelect( select => {
-	const { getBlockOrder } = select( 'core/block-editor' )
-	return {
-		hasInnerBlocks: getBlockOrder( props.clientId ).length > 0,
-	}
-}, [ props.clientId ] )
+const hasInnerBlocks = useHasInnerBlocks( props.clientId )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/block/blockquote/edit.js` around lines 62 - 67, Extract the duplicated
selector logic that computes hasInnerBlocks into a shared hook named
useHasInnerBlocks(clientId): move the useSelect call that references
getBlockOrder and props.clientId into the new hook so callers (like
BlockquoteEdit) call const hasInnerBlocks = useHasInnerBlocks(props.clientId);
ensure the hook imports useSelect from `@wordpress/data`, returns a boolean based
on getBlockOrder(clientId).length > 0, and update all block edit files that
currently duplicate the useSelect pattern to use this new hook.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/block/blockquote/edit.js`:
- Around line 62-67: Extract the duplicated selector logic that computes
hasInnerBlocks into a shared hook named useHasInnerBlocks(clientId): move the
useSelect call that references getBlockOrder and props.clientId into the new
hook so callers (like BlockquoteEdit) call const hasInnerBlocks =
useHasInnerBlocks(props.clientId); ensure the hook imports useSelect from
`@wordpress/data`, returns a boolean based on getBlockOrder(clientId).length > 0,
and update all block edit files that currently duplicate the useSelect pattern
to use this new hook.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f186c139-d524-4bed-a56e-15a968ecd7b5

📥 Commits

Reviewing files that changed from the base of the PR and between 783643d and 1817b7f.

📒 Files selected for processing (4)
  • src/block/blockquote/edit.js
  • src/block/expand/edit.js
  • src/block/price/edit.js
  • src/block/video-popup/edit.js

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blockquote Block - deleted icon reappears after page refresh Price Block - removed price text reappears upon page reload

1 participant