🕳️ fix: Guard Sparse Content Parts in Message Nav Preview (#13632)

This commit is contained in:
Ravi Kumar L 2026-06-09 16:24:48 -04:00 committed by GitHub
parent a91c45d687
commit cecaa174ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View file

@ -3,8 +3,8 @@ import { ChevronUp, ChevronDown } from 'lucide-react';
import { ContentTypes } from 'librechat-data-provider';
import { HoverCard, HoverCardTrigger, HoverCardPortal, HoverCardContent } from '@librechat/client';
import type { TMessage, TMessageContentParts } from 'librechat-data-provider';
import { useGetMessagesByConvoId } from '~/data-provider';
import { useMessagesConversation, useMessagesSubmission } from '~/Providers';
import { useGetMessagesByConvoId } from '~/data-provider';
import { useLocalize } from '~/hooks';
import { cn } from '~/utils';
@ -19,7 +19,7 @@ function extractPreviewFromContent(content?: TMessageContentParts[]): string {
return '';
}
for (const part of content) {
if (part.type !== ContentTypes.TEXT) {
if (part?.type !== ContentTypes.TEXT) {
continue;
}
const textField = part.text;

View file

@ -9,6 +9,13 @@ type TestMessage = {
conversationId?: string;
text?: string;
isCreatedByUser?: boolean;
content?: Array<
| {
type?: string;
text?: string | { value?: string };
}
| undefined
>;
};
const mockUseGetMessagesByConvoId = jest.fn();
@ -294,6 +301,22 @@ describe('MessageNav', () => {
expect(text.endsWith('...')).toBe(true);
expect(text.length).toBe(83);
});
it('skips sparse content entries when deriving preview text', () => {
const messages = [
buildMessage({
messageId: 'a',
text: '',
isCreatedByUser: true,
content: [undefined, { type: 'text', text: 'content-preview' }],
}),
buildMessage({ messageId: 'b', text: 'bravo' }),
buildMessage({ messageId: 'c', text: 'charlie', isCreatedByUser: true }),
];
const { container } = renderNav(messages);
const preview = container.querySelectorAll('[data-testid="hover-card-content"] p')[0];
expect(preview).toHaveTextContent('content-preview');
});
});
describe('accessibility', () => {