Skip to content

Commit 3958adc

Browse files
fix: add rounded-16 to CollapsedRepliesPreview and prevent rendering with no replies
- Add rounded-16 class to button with proper class order - Add guard clause to return null when no replies exist - Fix React hooks rules violation by moving useMemo before early return - Update test to use proper testing library methods Co-authored-by: Chris Bongers <rebelchris@users.noreply.github.com>
1 parent d3eebc5 commit 3958adc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/shared/src/components/comments/CollapsedRepliesPreview.spec.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ describe('CollapsedRepliesPreview', () => {
5353
jest.clearAllMocks();
5454
});
5555

56+
it('should not render when there are no replies', () => {
57+
renderComponent([], onExpand);
58+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
59+
});
60+
5661
it('should render single reply text correctly', () => {
5762
const replies = [createReply('r1', 'u1', 'user1')];
5863
renderComponent(replies, onExpand);

packages/shared/src/components/comments/CollapsedRepliesPreview.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ export default function CollapsedRepliesPreview({
1717
replies,
1818
onExpand,
1919
className,
20-
}: CollapsedRepliesPreviewProps): ReactElement {
20+
}: CollapsedRepliesPreviewProps): ReactElement | null {
2121
const uniqueAuthors = useMemo(() => {
22+
if (!replies.length) {
23+
return [];
24+
}
25+
2226
const seen = new Set<string>();
2327

2428
return replies.reduce<Comment['author'][]>((authors, { node }) => {
@@ -37,11 +41,15 @@ export default function CollapsedRepliesPreview({
3741
const replyCount = replies.length;
3842
const replyText = replyCount === 1 ? 'reply' : 'replies';
3943

44+
if (!replies.length) {
45+
return null;
46+
}
47+
4048
return (
4149
<button
4250
type="button"
4351
className={classNames(
44-
'flex w-full cursor-pointer items-center gap-2 px-4 py-3 hover:bg-surface-hover',
52+
'flex w-full cursor-pointer items-center gap-2 rounded-16 px-4 py-3 hover:bg-surface-hover',
4553
className,
4654
)}
4755
onClick={onExpand}

0 commit comments

Comments
 (0)