-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
Size Change: +5.6 kB (+1%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @carolinan ! I left a small comment but this looks good.
@@ -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 ) { |
There was a problem hiding this comment.
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 ) };
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description
The Post Categories & Post Tags Blocks don't work if you insert them into a page.
After adding either of these blocks into your content, you simply get a spinning icon and nothing else.
This PR attempts to check if the
types
supported by the term is the same as the current post type.If the
termId
does not exist, and if thetypes
and post type are not the same, the loading state is returned as false,and the spinner is no longer shown.
Instead of the spinner, the message that is displayed is "No tags" and "No categories" respectively.
Closes #34212
How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).