Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InnerBlocks: Fix regression where setting a template also locked it #7723

Closed

Conversation

jorgefilipecosta
Copy link
Member

Regressed in: #7234

InnerBlocks applied template sync on each update. This created a bug where if locking was not set when inserting or removing a block the template mechanism reverted the action.
This commit makes sure we only sync with the template if templateLock equals "all" or if the template contains inner blocks and the block does not contain any inner block.

How has this been tested?

I checked columns block continues to work as before.
I added the test blocks available in https://gist.github.com/jorgefilipecosta/2bac096fe3be7f6ff0de7452292161cb.
I added the locking all and checked we cannot insert blocks on the locking all. But we can insert on the no locking block inside (on master we can't).
I added the "no locking" and "locking unset" blocks and verified in both of them I can insert an image.

InnerBlocks applied template sync on each update. This created a bug where if locking was not set when inserting or removing a block the template mechanism reverted the action.
This commit makes sure we only sync with the template if templateLock equals "all" or if the template contains inner blocks and the blocks do not contain them any inner block.
@jorgefilipecosta jorgefilipecosta added this to the 3.2 milestone Jul 5, 2018
@jorgefilipecosta jorgefilipecosta added the [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P label Jul 5, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the fix/innerblocks-template-sets-a-locking branch from 8aa2481 to 128946a Compare July 5, 2018 13:13
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

What cases is this lifecycle method trying to cover? We should be clear with this via inline comments and/or tests. I fault myself for this with recent refactorings. One case I don't think we're covering is the template change; if the developer passes a new template, don't we want to effect it even if there is no "mismatch" ? Seems like the fix may be to change isTemplateInnerBlockMismatch to account for the templateLock === 'all', yeah?


this.updateNestedSettings();
if ( templateLock !== 'all' && block.innerBlocks && block.innerBlocks.length > 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

We're checking truthiness of block.innerBlocks before testing length here but not below in the assignment of isTemplateInnerBlockMismatch. We should be consistent one way or the other, depending on whether we actually need to be defensive.

@aduth
Copy link
Member

aduth commented Jul 5, 2018

Also, there's too much logic going on in a lifecycle method here. This should probably be separated out and clearly documented (incl. self-documenting named function). Can this be consolidated into synchronizeBlocksWithTemplate ?

@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Jul 5, 2018

One case I don't think we're covering is the template change; if the developer passes a new template, don't we want to effect it even if there is no "mismatch" ?

We should only do that for the case where templateLock is all or for the case where we don't have any innerBlocks yet. For the other cases, as we can remove blocks (or even insert if locking != insert), on template change, we should not apply the sync because we would not know if we are removing something the user did intentionally.

@aduth
Copy link
Member

aduth commented Jul 5, 2018

Why can we make that assumption in component updates, but not for component mount. Wouldn't it also be an issue for reloading an editor where the template doesn't match the blocks from in content?

@aduth
Copy link
Member

aduth commented Jul 5, 2018

I don't recall why we care to look at the template blocks length at all to determine mismatch; I see it's buggy without, but bugs I'm observing seems not totally related. Digging more...

@jorgefilipecosta
Copy link
Member Author

Closed in favor of #7732.

@aduth aduth deleted the fix/innerblocks-template-sets-a-locking branch July 5, 2018 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants