Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Terms: Prevent the block from breaking on pages #35957

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/block-library/src/post-terms/use-post-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

term.types is an array and also we could combine this check with inside the existing if ( !termIds ) like this:

return { isLoading: term?.postTerms?.includes( postType ) };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how it works but I have made the change.

Copy link
Contributor

@ntsekouras ntsekouras Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If termIds from useEntityProp resolve properly they will return an empty array, which is handled right below. So when if ( !termIds ) is either while resolving or it will never find the requested entity and termIds will be undefined for ever. Makes sense?

return { isLoading: false };
}

const visible = term?.visibility?.publicly_queryable;
if ( ! visible ) {
return {
Expand Down