Navigation: Avoid List View changing position when navigation block saves#76659
Navigation: Avoid List View changing position when navigation block saves#76659
Conversation
… to avoid a remount
|
Size Change: +122 B (0%) Total Size: 7.66 MB
ℹ️ View Unchanged
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| 'wp_navigation', | ||
| 'title' | ||
| 'title', | ||
| currentMenuId |
There was a problem hiding this comment.
After moving MenuInspectorControls out from under the EntityProvider it can no longer get the menu Id through context, so it has to be provided explicitly. The component already has access to it, so it's easy enough.
|
Flaky tests detected in 80434f2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23284532063
|
ntsekouras
left a comment
There was a problem hiding this comment.
Tested and looks good to me, thanks!
Not from this PR, but I was wondering if MenuInspectorControls could be in a single variable like stylingInspectorControls.
…aves (#76659) * Render MenuInspectorControls and stylingInspectorControls at the root to avoid a remount * Make NavigationMenuSelector not dependent on EntityProvider ---- Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: 6c9509f |
This updates the pinned hash from the `gutenberg` from `487a096a9782ba6110a7686d7b4b2d0c55ed1b06` to `2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d`. The following changes are included: - RTC: Backport race condition fix (WordPress/gutenberg#76649) - Fix navigation block rendering unit test (WordPress/gutenberg#76685) - Hide Additional CSS controls when block is inside contentOnly editing mode (WordPress/gutenberg#76512) - RTC: Increase polling intervals, increase polling on primary room only (WordPress/gutenberg#76704) - Navigation: Avoid List View changing position when navigation block saves (WordPress/gutenberg#76659) - Fix navigation block unit test and e2e test (WordPress/gutenberg#76692) - Fix locked content when switching to a different template without exiting 'Edit pattern' (WordPress/gutenberg#76710) - Metabox: Fix checkbox style in sidebar (WordPress/gutenberg#76718) - Stop keeping stale controlled blocks after reset (WordPress/gutenberg#76591) - Gate client-side media processing as plugin-only (WordPress/gutenberg#76700) A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/487a096a9782ba6110a7686d7b4b2d0c55ed1b06…2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d. Log created with: git log --reverse --format="- %s" 487a096a9782ba6110a7686d7b4b2d0c55ed1b06..2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy See #64595. git-svn-id: https://develop.svn.wordpress.org/trunk@62076 602fd350-edb4-49c9-b593-d223f7449a82
This updates the pinned hash from the `gutenberg` from `487a096a9782ba6110a7686d7b4b2d0c55ed1b06` to `2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d`. The following changes are included: - RTC: Backport race condition fix (WordPress/gutenberg#76649) - Fix navigation block rendering unit test (WordPress/gutenberg#76685) - Hide Additional CSS controls when block is inside contentOnly editing mode (WordPress/gutenberg#76512) - RTC: Increase polling intervals, increase polling on primary room only (WordPress/gutenberg#76704) - Navigation: Avoid List View changing position when navigation block saves (WordPress/gutenberg#76659) - Fix navigation block unit test and e2e test (WordPress/gutenberg#76692) - Fix locked content when switching to a different template without exiting 'Edit pattern' (WordPress/gutenberg#76710) - Metabox: Fix checkbox style in sidebar (WordPress/gutenberg#76718) - Stop keeping stale controlled blocks after reset (WordPress/gutenberg#76591) - Gate client-side media processing as plugin-only (WordPress/gutenberg#76700) A full list of changes can be found on GitHub: https://github.com/WordPress/gutenberg/compare/487a096a9782ba6110a7686d7b4b2d0c55ed1b06…2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d. Log created with: git log --reverse --format="- %s" 487a096a9782ba6110a7686d7b4b2d0c55ed1b06..2ee7ede6be6d4e55d5c7047394c5c4e0ea8d521d | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy See #64595. Built from https://develop.svn.wordpress.org/trunk@62076 git-svn-id: http://core.svn.wordpress.org/trunk@61358 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What?
Note: best reviewed with white space hidden (PR is mostly moving some lines of code around)
Fixes a small glitch with the Navigation block's custom List View.
If you edit a template part or pattern that has multiple 'unsaved' navigation blocks (e.g. a menu that the theme provided) when making some changes to the navigation block that cause it to save, the list view panel for that block jumps to the end of the sidebar. (see the videos for an example)
Why?
The issue is that with the way the NavigationEdit component is structured, it causes the List View to remount during the save process. Remounting causes it to unregister and re-register its slotfill, and because fills are registered in a queue, the panel jumps to the end.
The remounting happens because the
MenuInspectorControlscomponent has different parents when unsaved compared to when its saved. There are different return statements that control this.When unsaved it just has
TagNameas a parent:gutenberg/packages/block-library/src/navigation/edit/index.js
Lines 967 to 994 in 11d9a83
When saved it has
EntityProviderandRecursionProvider:gutenberg/packages/block-library/src/navigation/edit/index.js
Lines 1090 to 1108 in 11d9a83
The different parents means react can't reconcile as the same across renders.
How?
The fix is to avoid the remounting by unnesting the
MenuInspectorControlscomponent. Since the component is rendered via a slot fill (a portal) it can be rendered at the root, which means it will render in a stable position and be reconciled consistently.I've also done the same for
stylingInspectorControlsfor consistency.Testing Instructions
It's best tested using a pattern or template part that has multiple navigation blocks.
The default TT5 footer is a good one. Make sure it's fully reset and not using a saved navigation block.
In trunk: After the loading spinner, the List View panel jumps to the end
In this PR: After the loading spinner, the List View panel stays in the same place.
Screenshots or screencast
Before
Kapture.2026-03-19.at.10.02.37.mp4
After
Kapture.2026-03-19.at.10.05.49.mp4
Use of AI Tools
None, I made this the old fashioned way