-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🖱️ fix: Message Scrolling UX; refactor: Frontend UX/DX Optimizations (#…
…3733) * refactor(DropdownPopup): set MenuButton `as` prop to `div` to prevent React warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button> * refactor: memoize ChatGroupItem and ControlCombobox components * refactor(OpenAIClient): await stream process finish before finalCompletion event handling * refactor: update useSSE.ts typing to handle null and undefined values in data properties * refactor: set abort scroll to false on SSE connection open * refactor: improve logger functionality with filter support * refactor: update handleScroll typing in MessageContainer component * refactor: update logger.dir call in useChatFunctions to log 'message_stream' tag format instead of the entire submission object as first arg * refactor: fix null check for message object in Message component * refactor: throttle handleScroll to help prevent auto-scrolling issues on new message requests; fix type issues within useMessageProcess * refactor: add abortScrollByIndex logging effect * refactor: update MessageIcon and Icon components to use React.memo for performance optimization * refactor: memoize ConvoIconURL component for performance optimization * chore: type issues * chore: update package version to 0.7.414
- Loading branch information
1 parent
ba9c351
commit 98b437e
Showing
20 changed files
with
288 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,71 @@ | ||
import { useMemo, memo } from 'react'; | ||
import React, { useMemo, memo } from 'react'; | ||
import { useGetEndpointsQuery } from 'librechat-data-provider/react-query'; | ||
import type { TMessage, TPreset, Assistant } from 'librechat-data-provider'; | ||
import type { TMessageProps } from '~/common'; | ||
import ConvoIconURL from '~/components/Endpoints/ConvoIconURL'; | ||
import { getEndpointField, getIconEndpoint } from '~/utils'; | ||
import Icon from '~/components/Endpoints/Icon'; | ||
|
||
function MessageIcon( | ||
props: Pick<TMessageProps, 'message' | 'conversation'> & { | ||
assistant?: Assistant; | ||
}, | ||
) { | ||
const { data: endpointsConfig } = useGetEndpointsQuery(); | ||
const { message, conversation, assistant } = props; | ||
|
||
const assistantName = assistant ? (assistant.name as string | undefined) : ''; | ||
const assistantAvatar = assistant ? (assistant.metadata?.avatar as string | undefined) : ''; | ||
|
||
const messageSettings = useMemo( | ||
() => ({ | ||
...(conversation ?? {}), | ||
...({ | ||
...(message ?? {}), | ||
iconURL: message?.iconURL ?? '', | ||
} as TMessage), | ||
}), | ||
[conversation, message], | ||
); | ||
|
||
const iconURL = messageSettings.iconURL; | ||
let endpoint = messageSettings.endpoint; | ||
endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint }); | ||
const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL'); | ||
|
||
if (message?.isCreatedByUser !== true && iconURL != null && iconURL.includes('http')) { | ||
const MessageIcon = memo( | ||
( | ||
props: Pick<TMessageProps, 'message' | 'conversation'> & { | ||
assistant?: Assistant; | ||
}, | ||
) => { | ||
const { data: endpointsConfig } = useGetEndpointsQuery(); | ||
const { message, conversation, assistant } = props; | ||
|
||
const assistantName = useMemo(() => assistant?.name ?? '', [assistant]); | ||
const assistantAvatar = useMemo(() => assistant?.metadata?.avatar ?? '', [assistant]); | ||
const isCreatedByUser = useMemo(() => message?.isCreatedByUser ?? false, [message]); | ||
|
||
const messageSettings = useMemo( | ||
() => ({ | ||
...(conversation ?? {}), | ||
...({ | ||
...(message ?? {}), | ||
iconURL: message?.iconURL ?? '', | ||
} as TMessage), | ||
}), | ||
[conversation, message], | ||
); | ||
|
||
const iconURL = messageSettings.iconURL; | ||
const endpoint = useMemo( | ||
() => getIconEndpoint({ endpointsConfig, iconURL, endpoint: messageSettings.endpoint }), | ||
[endpointsConfig, iconURL, messageSettings.endpoint], | ||
); | ||
|
||
const endpointIconURL = useMemo( | ||
() => getEndpointField(endpointsConfig, endpoint, 'iconURL'), | ||
[endpointsConfig, endpoint], | ||
); | ||
|
||
if (isCreatedByUser !== true && iconURL != null && iconURL.includes('http')) { | ||
return ( | ||
<ConvoIconURL | ||
preset={messageSettings as typeof messageSettings & TPreset} | ||
context="message" | ||
assistantAvatar={assistantAvatar} | ||
endpointIconURL={endpointIconURL} | ||
assistantName={assistantName} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<ConvoIconURL | ||
preset={messageSettings as typeof messageSettings & TPreset} | ||
context="message" | ||
assistantAvatar={assistantAvatar} | ||
endpointIconURL={endpointIconURL} | ||
<Icon | ||
isCreatedByUser={isCreatedByUser} | ||
endpoint={endpoint} | ||
iconURL={!assistant ? endpointIconURL : assistantAvatar} | ||
model={message?.model ?? conversation?.model} | ||
assistantName={assistantName} | ||
size={28.8} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Icon | ||
{...messageSettings} | ||
endpoint={endpoint} | ||
iconURL={!assistant ? endpointIconURL : assistantAvatar} | ||
model={message?.model ?? conversation?.model} | ||
assistantName={assistantName} | ||
size={28.8} | ||
/> | ||
); | ||
} | ||
|
||
export default memo(MessageIcon); | ||
}, | ||
); | ||
|
||
MessageIcon.displayName = 'MessageIcon'; | ||
|
||
export default MessageIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.