mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-25 08:56:10 +00:00
🕳️ fix: Guard Sparse Content Parts in Message Nav Preview (#13632)
This commit is contained in:
parent
a91c45d687
commit
cecaa174ce
2 changed files with 25 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue