diff --git a/packages/fields/src/fields/slug/slug-view.tsx b/packages/fields/src/fields/slug/slug-view.tsx index 5aa1db048bd413..c418fafd1a9af9 100644 --- a/packages/fields/src/fields/slug/slug-view.tsx +++ b/packages/fields/src/fields/slug/slug-view.tsx @@ -10,7 +10,7 @@ import type { BasePost } from '../../types'; import { getSlug } from './utils'; const SlugView = ( { item }: { item: BasePost } ) => { - const slug = item ? getSlug( item ) : ''; + const slug = typeof item === 'object' ? getSlug( item ) : ''; const originalSlugRef = useRef( slug ); useEffect( () => { @@ -21,7 +21,7 @@ const SlugView = ( { item }: { item: BasePost } ) => { const slugToDisplay = slug || originalSlugRef.current; - return `${ slugToDisplay ?? '' }`; + return `${ slugToDisplay }`; }; export default SlugView; diff --git a/packages/fields/src/fields/slug/utils.ts b/packages/fields/src/fields/slug/utils.ts index 992a21d44ccf65..a422afaf898f96 100644 --- a/packages/fields/src/fields/slug/utils.ts +++ b/packages/fields/src/fields/slug/utils.ts @@ -8,7 +8,7 @@ import { cleanForSlug } from '@wordpress/url'; import type { BasePost } from '../../types'; import { getItemTitle } from '../../actions/utils'; -export const getSlug = ( item: BasePost ) => { +export const getSlug = ( item: BasePost ): string => { return ( item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString() );