From ba47f43d8999a0b9a4be2d9fa7f0e92434522afe Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 10 Dec 2024 17:29:17 +0100 Subject: [PATCH] Renders `DataForm` component only when data has been fetched (#67694) Co-authored-by: gigitux Co-authored-by: youknowriad Co-authored-by: oandregal --- .../src/components/post-edit/index.js | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/edit-site/src/components/post-edit/index.js b/packages/edit-site/src/components/post-edit/index.js index d32666bcf3aa1b..97484c89ed670b 100644 --- a/packages/edit-site/src/components/post-edit/index.js +++ b/packages/edit-site/src/components/post-edit/index.js @@ -34,17 +34,22 @@ const fieldsWithBulkEditSupport = [ function PostEditForm( { postType, postId } ) { const ids = useMemo( () => postId.split( ',' ), [ postId ] ); - const { record } = useSelect( + const { record, hasFinishedResolution } = useSelect( ( select ) => { + const args = [ 'postType', postType, ids[ 0 ] ]; + + const { + getEditedEntityRecord, + hasFinishedResolution: hasFinished, + } = select( coreDataStore ); + return { record: - ids.length === 1 - ? select( coreDataStore ).getEditedEntityRecord( - 'postType', - postType, - ids[ 0 ] - ) - : null, + ids.length === 1 ? getEditedEntityRecord( ...args ) : null, + hasFinishedResolution: hasFinished( + 'getEditedEntityRecord', + args + ), }; }, [ postType, ids ] @@ -159,12 +164,14 @@ function PostEditForm( { postType, postId } ) { return ( - + { hasFinishedResolution && ( + + ) } ); }