Skip to content
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 block: return undefined from useEffect #45239

Merged
merged 1 commit into from Oct 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions packages/block-library/src/navigation/edit/index.js
Expand Up @@ -272,7 +272,7 @@ function Navigation( {
fallbackNavigationMenus?.length > 0 ||
classicMenus?.length !== 1
) {
return false;
return;
}

// If there's non fallback navigation menus and
Expand Down Expand Up @@ -481,24 +481,22 @@ function Navigation( {

// Prompt the user to publish the menu they have set as a draft
const isDraftNavigationMenu = navigationMenu?.status === 'draft';
useEffect( async () => {
useEffect( () => {
hideMenuAutoPublishDraftNotice();
if ( ! isDraftNavigationMenu ) return;
try {
await editEntityRecord(
'postType',
'wp_navigation',
navigationMenu?.id,
{
status: 'publish',
},
{ throwOnError: true }
);
} catch {
if ( ! isDraftNavigationMenu ) {
return;
}
editEntityRecord(
'postType',
'wp_navigation',
navigationMenu?.id,
{ status: 'publish' },
{ throwOnError: true }
).catch( () => {
showMenuAutoPublishDraftNotice(
__( 'Error occurred while publishing the navigation menu.' )
);
}
} );
}, [ isDraftNavigationMenu, navigationMenu ] );

const stylingInspectorControls = (
Expand Down