-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation block: Try using a templated page list when there are no menus or inner blocks #44596
Conversation
Size Change: +51 B (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
…ks, replacing the current effect
bd7e49e
to
bcdeea8
Compare
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.
Yes, this is great except that - the same as when I tried it - it will create an undo item. Can we use this approach which is much cleaner and nicer but also __unstableMarkNextChangeAsNotPersistent
?
The other effect is that immediately on selecting the page list a new navigation is created.
The intent of the original PR is to make the page list a plaeholder, which acts like a placeholder (does not create undo levels), and also to avoid surprising interaction (automagically creating nav menus).
I have been AFK so apologies for being behind in reviews. Thanks for raising this PR - the declarative approach seems much nicer on first glance.
We should definitely avoid this as we agreed previously that we needed user interaction in order to go from uncontrolled -> controlled inner blocks. Is it possible to make it clear that user must modify the inner blocks template in order to trigger creation of a sync'd Nav menu. Unrelated: @scruffian this is also a great example of where missing test causes previous decisions made about the functionality of the block to be vulnerable to regression. If these expectations were encoded in the tests we wouldn't need to rely on contributor's spotting potential problems. |
Thanks for raising those problems. I think it's worth looking at why that happens. Those both may be additional bugs to solve. |
What?
See #44594.
Replaces the code that runs
replaceInnerBlocks
to create a default page list with an inner blockstemplate
prop.Why?
The result should hopefully be exactly the same, but this makes the code more declarative. Effects that run on mount are considered a code quality issue, and it's very easy to cause bugs (see the recent issue with the group block - #44176). If there's an option to replace them, it's good to do that.
How?
The code in
trunk
results in the following:replaceInnerBlocks( clientId, [ createBlock( 'core/page-list' ) ] );
UncontrolledInnerBlocks
is conditionally rendered becausehasUncontrolledInnerBlocks
is nowtrue
andisEntityAvailable
is stillfalse
. It shows the new Page List block.In this PR that switches to:
UncontrolledInnerBlocks
conditionally renders wheneverisEntityAvailable
is false.Testing Instructions
I also tested a couple of other things: