Skip to content

Commit

Permalink
QuickEdit: prevent site-editor from crashing when data is not an obje…
Browse files Browse the repository at this point in the history
…ct (#67577)

Co-authored-by: oandregal <[email protected]>
Co-authored-by: gigitux <[email protected]>
  • Loading branch information
3 people authored and michalczaplinski committed Dec 5, 2024
1 parent 1c3d961 commit 558b334
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 558b334

Please sign in to comment.