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

Latest Posts: Declare 'hasPosts' before 'inspectorControls' #32160

Merged
merged 1 commit into from
May 26, 2021
Merged
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
};
}, [] );

const hasPosts = !! latestPosts?.length;
Copy link
Member

Choose a reason for hiding this comment

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

Admittedly, I have not used the optional chaining before and am not really grasping it after reading about it briefly.

That said, I tested it out using a ZIP built from the PR and I was unable to reproduce this error in #31847. I tried across a couple different themes too and when no posts exist in the database.

const inspectorControls = (
<InspectorControls>
<PanelBody title={ __( 'Post content settings' ) }>
Expand Down Expand Up @@ -412,7 +413,6 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
} ),
} );

const hasPosts = Array.isArray( latestPosts ) && latestPosts.length;
if ( ! hasPosts ) {
return (
<div { ...blockProps }>
Expand Down