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
Inner Blocks: Respecting locking in display of default block appender #7732
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,23 +22,23 @@ import BlockList from '../block-list'; | |
import { withBlockEditContext } from '../block-edit/context'; | ||
|
||
class InnerBlocks extends Component { | ||
componentDidMount() { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.updateNestedSettings(); | ||
} | ||
|
||
componentDidMount() { | ||
this.synchronizeBlocksWithTemplate(); | ||
} | ||
|
||
componentDidUpdate( prevProps ) { | ||
const { template, block } = this.props; | ||
const { template } = this.props; | ||
|
||
this.updateNestedSettings(); | ||
|
||
const hasTemplateChanged = ! isEqual( template, prevProps.template ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we compare using equal while on allowedBlocks we compare by reference. We should probably decide on one of the approaches while comparing by reference is more performant this comparison is more developer friendly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree we need consistency here. Not sure performance is a fair measurement in this case though, since in almost all cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our docs already contain the samples using a constant.
For dynamic cases, we can save a reference in the state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may be better off doing a deep equality check on the allowed blocks. It's not too much more effort to dive into the array of strings, and avoids a much more concerning overhead if the developer doesn't assign allowed blocks as a constant reference (which itself is overhead in its own right). I'll plan to open a separate pull request proposing this. |
||
const isTemplateInnerBlockMismatch = ( | ||
template && | ||
block.innerBlocks.length !== template.length | ||
); | ||
|
||
if ( hasTemplateChanged || isTemplateInnerBlockMismatch ) { | ||
if ( hasTemplateChanged ) { | ||
this.synchronizeBlocksWithTemplate(); | ||
} | ||
} | ||
|
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 don't really like that we rely on specific component lifecycle to effect nested locking.