-
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: Don't create duplicate wp_navigation CPTs when updating inner blocks #48587
Conversation
Size Change: +26 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
This is very similar to the original fix I proposed in #47884. |
@scruffian Please could you add a little more detail around this? All your changes are to the Navigation block itself yet here you refer to the Navigation Link block. |
I we go with this then we won't need this PR |
This was made obsolete by the new fallbacks endpoint. Closing... |
What?
When creating a navigation menu from the state of navigation when it has uncontrolled inner blocks, we are currently creating two wp_navigation CPTs. This is because
blocks
gets modified by the Navigation Link block edit component, triggering theuseEffect
twice.To avoid this I tried using the status of the
useCreateNavigationMenu
hook, but the problem with this approach is that state is set asynchronously, whereas the changes toblocks
happens immediately, so the useEffect is still called twice.To get around this I have tried using a ref which stores the state of the useEffect allowing us to ensure that it is only called once. This feels like a bit of a work around, but I couldn't think of a better option, except removing
blocks
from the dependencies (#48220).Testing Instructions