fix: only apply template on first insert so unlocked changes persist …#3692
fix: only apply template on first insert so unlocked changes persist …#3692
Conversation
📝 WalkthroughWalkthroughFour block edit components ( Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
🤖 Pull request artifacts
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/block/blockquote/edit.js (1)
62-67: Consider extractinghasInnerBlocksselector 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
📒 Files selected for processing (4)
src/block/blockquote/edit.jssrc/block/expand/edit.jssrc/block/price/edit.jssrc/block/video-popup/edit.js
…on referesh
fixes #3677
fixes #3556
Variation change after inserting the block still works.
Summary by CodeRabbit