-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix: InnerBlocks should only force the template on directly set lockings #16973
Fix: InnerBlocks should only force the template on directly set lockings #16973
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Howdy!
During our work with Header/Footers with FSE, we experienced a bug (Automattic/wp-calypso#35429) related to adding a Cover block inside the header. When rendering the block in the page editor (inside Disabled
and with the editor settings having templateLock='all'
), several of the cover's children blocks would not be rendered. I traced it back to InnerBlocks
, where it was synchronizing the blocks with the template and replacing most of the content.
I found this PR and ran it in Gutenberg / FSE test environment and it resolves the bug! 👍
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' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is getTemplateLock
useful now? Should we remove inheritance entirely?
I have to admit, I'm having trouble understanding how locking in nested context work in relationship with the global template, and the template provided as prop... If I'm having trouble understanding it, others will. I'm wondering if we should have a document that clarifies how it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What sort of documentation would we need to unblock the PR? An example section in the handbook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, I don't think documentation should block the PR. I was just having hard time understanding how this work, especially thinking of all contexts. (CPT template, prop template, CPT lock, prop lock...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @youknowriad,
Is getTemplateLock useful now?
We only had one usage of it. I guess we can remove and inline its logic. The change was applied.
Should we remove inheritance entirely?
Nice question, I think the inheritance mechanism is useful. E.g.: without it, if I use group with some paragraphs inside or a cover in a CPT with locking all, inside the group or cover the user will always be able to do anything and locking has no effect.
If the user has a locking all and wants in a specific cover block to allow the user to do anything that's also possible nowadays. The developer can create a container block that sets locking to false and in the template set the cover to be inside that block.
So I think inheritance together with child/container blocks provides a powerful mechanism and removing inheritance is removing some options.
Yes, I agree that the logic is complex and hard to understand. I will create a separate PR that tries to document how these mechanisms work so we don't block this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So With these changes, if we want to lock the synchronization we need to set it up explicitly?
<div className="wp-block-cover__inner-container">
<InnerBlocks
template={ INNER_BLOCKS_TEMPLATE }
templateLock="all"
/>
</div>
Just FYI, I've been working on previewing different blocks using the <BlockPreview />
component, getting into issues specifically with core/cover
and core/image-text
blocks.
This PR fixes the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So With these changes, if we want to lock the synchronization we need to set it up explicitly?
Exactly the template synchronization only happens if templateLock all is explicitly set. If the cover block was changed to that code sample the synchronization would happen.
6e173ad
to
9456479
Compare
9456479
to
53085c2
Compare
Hi @gwwar, @noahtallen, @youknowriad, thank you for checking/reviewing this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no reason to block this PR more. Thanks Jorge
Supersedes: #16882
Currently, InnerBlocks forces the template when locking is all even if the locking is inherited.
This logic is not correct, because if block used in a template contains another template, the inner blocks for that block set on the parent template will be ignored as the child will inherit the locking all and the template of the child will start to be forced.
This PR updates the InnerBlocks logic to only force the template if the locking all is directly set and not inherited. In cases, the locking all is inherited it should be the template of the parent managing the inner blocks.
How has this been tested?
I pasted the following code in functions.php:
I created a new Locked All Post and I verified the InnerBlocks set for media-text and cover appear as expected.
Props to @oxyc for bringing this issue for our attention and proposing an initial fix for the media text-specific case.