-
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 auto Nav menu creation due to page list inner blocks #46223
Fix auto Nav menu creation due to page list inner blocks #46223
Conversation
Size Change: +116 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
innerBlocksAreDirty = ! isEqual( | ||
originalPageListBlockWithoutInnerBlocks, | ||
currentPageListBlockWithoutInnerBlocks | ||
); |
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.
Referential equality check is not possible here because we are creating two new objects using the de-structuring. Similarly we cannot mutate the original objects [to get only inner blocks] because that would invalidate future checks of originalBlocks
.
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
Overall I'm not convinced this approach is robust enough. I can't put my finger on why yet but we need to be careful before we merge this one. We could also consider a more generic solution that somehow makes use of |
@talldan I wonder if we could consider using the |
This comment was marked as resolved.
This comment was marked as resolved.
@georgeh Thank you. This is interesting. Does the same happen for you on |
@georgeh what theme are you testing with? |
I think that selector was around when I originally wrote some of this code, and it didn't work or had some caveats. Possibly the issue is that inner blocks need to render before It's hard to say for sure though, as the code has changed a lot and what was once an issue may no longer be an issue. |
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
Not sure how to proceed here. We need
I'm not super happy with how "hacky" this code feels but it does improve the experience for the user from what we have now which is not great at all with those Menus being auto-created. |
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.
This works for me. As noted, there are still bugs if the block provides both Page List and other blocks. I think we should merge this can create a follow up issue to consider more cases, but this will cover most scenarios so I wouldn't want to block it on other edge cases.
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.
This is testing correctly for me, all the testing instructions were working as expected
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'm seeing the same as @georgeh when I test this.
- Testing with Twenty Twenty-Three
- Deleted all the Navigation Menus
With this PR:
- Inserting a Navigation Block creates an empty block:
- Inserting a Page List creates a 'primary' Navigation Menu on save with all my pages (which I think is correct, just confirming)
On trunk:
- Inserting a Navigation Block creates a 'Primary' Navigation Menu without needing to save the Site Editor or any other trigger. The default page list is my top level pages only.
- Inserting a Page List inserts a list of all my pages, but doesn't create a new menu (maybe it's updating Primary?)
- The nav block performance seems a lot worse on trunk compared to this PR
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
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.
b0b9a42 this is a lot more elegant, and fixes potential future problems as well
Excellent work and persistence 👏🏻 🙇🏻
packages/block-library/src/navigation/edit/unsaved-inner-blocks.js
Outdated
Show resolved
Hide resolved
As a follow up let's explore using whether the block is "locked" as the factor to determine whether the block's |
Co-authored-by: Andrei Draganescu <[email protected]>
e68865e
to
ec45184
Compare
@scruffian @draganescu I added some test coverage here #46329 |
|
…6223) * Add exception for page list to ignore its inner blocks * Explain what is going on * Only consider the first block * Remove debugging * Be specific in the referential equality check comments * Ditch Lodash for Fast Deep Equal * Use customised conditional deep equality * Remove unnecessary let * Add comments for context * Fix grammar Co-authored-by: Andrei Draganescu <[email protected]> * Target fix to Page List only Co-authored-by: Andrei Draganescu <[email protected]>
What?
Fixes bug whereby the fallback Page List in the Navigation block was automatically creating a new Navigation Menu (post) on load.
Why?
This was happening because Page List has now been converted to use InnerBlocks. It is dynamic in the sense that the Page List Items are loaded from the REST API and thus the
.innerBlocks
property changes as the data is received.innerBlocks
is[]
innerBlocks
is an array of blocksThe
UncontrolledInnerBlocks
component in the Nav block checks for changes to the uncontrolled inner blocks and if there are any changes it considers the blocks to have become "dirty" and triggers the creation of a Navigation Menu.Unfortunately due to the dynamic population of inner blocks in the Page List block (as described above) this behaviour now caused the auto creation of a menu on insertion.
How?
The fix is currently achieved by adding a specific condition for Page List to ignore the inner blocks and only check for changes to the block's other properties (i.e.: we ignore changes to inner blocks of the Page List block).
This results in the dynamic changes to
innerBlocks
being ignored and thus the Nav Men is not auto created. However if you make other changes to the Nav block's inner blocks such as:...the Nav Menu will be correctly auto created as before.
Testing Instructions
This needs careful testing.
Before all tests please clear your Nav Menus at http://localhost:8888/wp-admin/edit.php?post_type=wp_navigation.
Test Page List
Edit
Test Adding New Block
Existing Inner Blocks
Testing Instructions for Keyboard
Screenshots or screencast
Co-authored-by: Maggie <[email protected]>
Co-authored-by: Ben Dwyer <[email protected]>