Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
fix: disable block commenting when postId is not number
  • Loading branch information
R1shabh-Gupta committed Sep 14, 2025
commit 423f051af4def460882fe450c13a903033e63256
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CommentAuthorInfo( { avatar, name, date } ) {
const { __experimentalDiscussionSettings } = getSettings();
const defaultAvatar = __experimentalDiscussionSettings?.avatarURL;
return {
currentUserAvatar: userData?.avatar_urls[ 48 ] ?? defaultAvatar,
currentUserAvatar: userData?.avatar_urls?.[ 48 ] ?? defaultAvatar,
currentUserName: userData?.name,
};
}, [] );
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ export default function CollabSidebar() {
};
}, [] );

const hasValidPostId = !! postId && typeof postId === 'number';

const { blockCommentId } = useSelect( ( select ) => {
const { getBlockAttributes, getSelectedBlockClientId } =
select( blockEditorStore );
Expand Down Expand Up @@ -336,6 +338,10 @@ export default function CollabSidebar() {
? AddCommentToolbarButton
: AddCommentButton;

if ( ! hasValidPostId ) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: We could just inline the check here. I usually avoid creating the variables if they're only used once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I update it like this, @Mamaduka? And would it be fine to add a comment?

// If postId is not a valid number, do not render the comment sidebar.
if ( ! ( !! postId && typeof postId === 'number' ) ) {
	return null;
}

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that looks about right.


return (
<>
<AddCommentComponent onClick={ openCollabBoard } />
Expand Down
Loading