Skip to content

Commit 0cc3500

Browse files
committed
fix: prevent commenting on empty blocks
1 parent c44ab57 commit 0cc3500

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/editor/src/components/collab-sidebar/add-comment.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
__experimentalVStack as VStack,
99
} from '@wordpress/components';
1010
import { store as blockEditorStore } from '@wordpress/block-editor';
11+
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
1112

1213
/**
1314
* Internal dependencies
@@ -29,16 +30,26 @@ export function AddComment( {
2930
showCommentBoard,
3031
setShowCommentBoard,
3132
} ) {
32-
const { clientId, blockCommentId } = useSelect( ( select ) => {
33-
const { getSelectedBlock } = select( blockEditorStore );
34-
const selectedBlock = getSelectedBlock();
35-
return {
36-
clientId: selectedBlock?.clientId,
37-
blockCommentId: selectedBlock?.attributes?.blockCommentId,
38-
};
39-
} );
33+
const { clientId, blockCommentId, isEmptyDefaultBlock } = useSelect(
34+
( select ) => {
35+
const { getSelectedBlock } = select( blockEditorStore );
36+
const selectedBlock = getSelectedBlock();
37+
return {
38+
clientId: selectedBlock?.clientId,
39+
blockCommentId: selectedBlock?.attributes?.blockCommentId,
40+
isEmptyDefaultBlock: selectedBlock
41+
? isUnmodifiedDefaultBlock( selectedBlock )
42+
: false,
43+
};
44+
}
45+
);
4046

41-
if ( ! showCommentBoard || ! clientId || undefined !== blockCommentId ) {
47+
if (
48+
! showCommentBoard ||
49+
! clientId ||
50+
undefined !== blockCommentId ||
51+
isEmptyDefaultBlock
52+
) {
4253
return null;
4354
}
4455

0 commit comments

Comments
 (0)