Skip to content

Commit

Permalink
Prevent site-editor from crashing when data is not an object
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 4, 2024
1 parent 88a3cef commit be60beb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/fields/src/fields/slug/slug-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { BasePost } from '../../types';
import { getSlug } from './utils';

const SlugView = ( { item }: { item: BasePost } ) => {
const slug = typeof item === 'object' ? getSlug( item ) : '';
const slug = getSlug( item );
const originalSlugRef = useRef( slug );

useEffect( () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/src/fields/slug/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import type { BasePost } from '../../types';
import { getItemTitle } from '../../actions/utils';

export const getSlug = ( item: BasePost ): string => {
if ( typeof item !== 'object' ) {
return '';
}

return (
item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString()
);
Expand Down

0 comments on commit be60beb

Please sign in to comment.