From d864801e166aefcfa7c1eff2b39589cb13b94d14 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Tue, 26 Oct 2021 14:23:08 +0200 Subject: [PATCH 1/2] Post terms: Do not fetch taxonomies that do not exist for the post type --- packages/block-library/src/post-terms/use-post-terms.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/block-library/src/post-terms/use-post-terms.js b/packages/block-library/src/post-terms/use-post-terms.js index 4539ea1c8df22..ae8ce3cbe612c 100644 --- a/packages/block-library/src/post-terms/use-post-terms.js +++ b/packages/block-library/src/post-terms/use-post-terms.js @@ -9,6 +9,11 @@ export default function usePostTerms( { postId, postType, term } ) { const [ termIds ] = useEntityProp( 'postType', postType, restBase, postId ); return useSelect( ( select ) => { + const termPostType = term?.types; + if ( ! termIds && termPostType !== postType ) { + return { isLoading: false }; + } + const visible = term?.visibility?.publicly_queryable; if ( ! visible ) { return { From 0d5a16bc5af25a334938a20f028d5f029bf944aa Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Thu, 28 Oct 2021 11:30:42 +0200 Subject: [PATCH 2/2] Move the check for supported post types --- packages/block-library/src/post-terms/use-post-terms.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/block-library/src/post-terms/use-post-terms.js b/packages/block-library/src/post-terms/use-post-terms.js index ae8ce3cbe612c..10fdb3ecfea55 100644 --- a/packages/block-library/src/post-terms/use-post-terms.js +++ b/packages/block-library/src/post-terms/use-post-terms.js @@ -9,11 +9,6 @@ export default function usePostTerms( { postId, postType, term } ) { const [ termIds ] = useEntityProp( 'postType', postType, restBase, postId ); return useSelect( ( select ) => { - const termPostType = term?.types; - if ( ! termIds && termPostType !== postType ) { - return { isLoading: false }; - } - const visible = term?.visibility?.publicly_queryable; if ( ! visible ) { return { @@ -24,7 +19,7 @@ export default function usePostTerms( { postId, postType, term } ) { } if ( ! termIds ) { // Waiting for post terms to be fetched. - return { isLoading: true }; + return { isLoading: term?.postTerms?.includes( postType ) }; } if ( ! termIds.length ) { return { isLoading: false };