-
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
Navigation: Update deps for the useEffect that creates navigation menus #47912
Conversation
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.
👍 LGTM
Size Change: +9.22 kB (+1%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in 586ecf4. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4133727171
|
return { | ||
isSaving: isSavingEntityRecord( 'postType', 'wp_navigation' ), | ||
draftNavigationMenus: getEntityRecords( | ||
// This is needed so that hasResolvedDraftNavigationMenus gives the correct status. |
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.
We have to keep this line, otherwise hasResolvedDraftNavigationMenus doesn't work.
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.
Can we just not check if navigation menus are resolved? We only need them because
Also ensure other navigation menus have loaded so an
// accurate name can be created.
Is there another way? Like wait for this when creating the default title instead?
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.
probably but i'm not sure how to do that!
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 don't think so actually - we also need to check if draft navigations are created because navigation we create is a draft. If I remove the check for hasResolvedDraftNavigationMenus
then two get 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.
When we call createNavigationMenu we do it with an empty title and there is a hook useGenerateDefaultNavigationTitle
where we alreadt check that we loaded all drafts already so we can assign the correct number.
getEntityRecords( ...DRAFT_MENU_PARAMS ),
getEntityRecords( ...PUBLISHED_MENU_PARAMS ),
] );
That means this guard here is kinda pointless.
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.
Why don't you pass in the isCreatingNavigationMenu
status of the createNavigationMenu
from the edit
component? That way we have a way of telling whether the conversion is in progress. That might help us block the 2nd menu because it gives a true status of the progress of the event we care about - namely: whether we are already creating a navigation.
Relying on various resolved states is surely prone to error.
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.
That doesn't stop us calling createNavigationMenu twice though does it?
I didn't mean that. I mean that hasResolvedDraftNavigationMenus
and hasResolvedNavigationMenus
are only needed here as deps because we check for them in the effect - but createNavigationMenu
which is the only result of the effect ALSO checks them - it seems they're not needed. And if they're not needed we don't need draftNavigationMenus
either.
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.
If I remove them then the problem comes back, so I think they are needed.
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.
Why don't you pass in the isCreatingNavigationMenu status of the createNavigationMenu from the edit component?
I don't think this will work. After the new navigation is created, the status is reset to idle
, but the block is still dirty as the new (draft) navigation hasn't yet loaded, so the effect gets triggered again, and we end up in a loop creating endless new menus.
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 didn't mean that. I mean that hasResolvedDraftNavigationMenus and hasResolvedNavigationMenus are only needed here as deps because we check for them in the effect - but createNavigationMenu which is the only result of the effect ALSO checks them - it seems they're not needed. And if they're not needed we don't need draftNavigationMenus either.
I don't think this will work, because although createNavigationMenu
does check the status of those dependencies, it happens after we call createNavigationMenu
, so the useEffect that is checking whether the blocks are in a dirty state will continue to be called.
I assume this needs to be backported to WP 6.2; I will update the labels. |
* Update deps for the useEffect that creates navigation menus * still check for draft menus * remvove unneeded code
I just cherry-picked this PR to the wp/6.2 branch to get it included in the next release: b715cda |
What?
The dependencies in the useEffect should match the variables we use inside the effect. Fixes #47881
Why?
Because otherwise the effect gets called multiple times.
How?
Matching the deps.
Testing Instructions
See #47881.