Skip to content

Commit

Permalink
Fix: InnerBlocks template sync only on direct locked all (#16973)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored and gziolo committed Aug 29, 2019
1 parent 0de53b8 commit 7ee9754
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ class InnerBlocks extends Component {
this.updateNestedSettings();
}

getTemplateLock() {
const {
templateLock,
parentLock,
} = this.props;
return templateLock === undefined ? parentLock : templateLock;
}

componentDidMount() {
const { innerBlocks } = this.props.block;
// only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists
if ( innerBlocks.length === 0 || this.getTemplateLock() === 'all' ) {
const { templateLock, block } = this.props;
const { innerBlocks } = block;
// Only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists directly on the block.
if ( innerBlocks.length === 0 || templateLock === 'all' ) {
this.synchronizeBlocksWithTemplate();
}

Expand All @@ -58,12 +51,12 @@ class InnerBlocks extends Component {
}

componentDidUpdate( prevProps ) {
const { template, block } = this.props;
const { template, block, templateLock } = this.props;
const { innerBlocks } = block;

this.updateNestedSettings();
// only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists
if ( innerBlocks.length === 0 || this.getTemplateLock() === 'all' ) {
// Only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists directly on the block.
if ( innerBlocks.length === 0 || templateLock === 'all' ) {
const hasTemplateChanged = ! isEqual( template, prevProps.template );
if ( hasTemplateChanged ) {
this.synchronizeBlocksWithTemplate();
Expand Down Expand Up @@ -92,11 +85,13 @@ class InnerBlocks extends Component {
blockListSettings,
allowedBlocks,
updateNestedSettings,
templateLock,
parentLock,
} = this.props;

const newSettings = {
allowedBlocks,
templateLock: this.getTemplateLock(),
templateLock: templateLock === undefined ? parentLock : templateLock,
};

if ( ! isShallowEqual( blockListSettings, newSettings ) ) {
Expand Down

0 comments on commit 7ee9754

Please sign in to comment.