-
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
Moves the menus state higher in the component tree #22345
Conversation
Size Change: +70 B (0%) Total Size: 833 kB
ℹ️ View Unchanged
|
useEffect( () => { | ||
if ( wpMenus?.length ) { | ||
setMenus( wpMenus ); | ||
setCurrentMenu( wpMenus[ 0 ].id ); | ||
} | ||
}, [ wpMenus ] ); |
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.
@draganescu As mentioned in #22340 (comment), I don't think this code will work, as the deleted menus get restored whenever wpMenus
changes.
This effect is listening for changes to wpMenus
, and whenver that happens setMenus( wpMenus )
on line 15 effectively undoes any of the changes to menus
performed by the onDeleteMenu
callback.
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.
It does currently work and it fixes the problem in #22340, but I agree that keeping a list of deletedItems
is better on the long run.
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.
Yeah, after further debugging I noticed it does usually work, I think it relies on the fact that typically when wpMenus
changes, the entity cache has been cleared and so deleted items are no longer present in wpMenus
.
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.
+1, this also affects the menu items themselves - we need one solution to rule them all :-)
Description
Closes #22340
How has this been tested?
Tested locally by:
Screenshots
Types of changes
Non breaking change. I moved the menus state in the
Layout
component. This doesn't make me happiest, asLayout
should not handle this data. However, until we fixcore/data
to refresh properly it is a decent solution.