Skip to content

Commit 6bc4f14

Browse files
committed
chat: fix performance issue rendering chatroom first time if any messages hidden; maxHeight threads
- if any message hidden would try to scroll to non-existent message, causing performance issue, so large rooom would appear blank for noticeable time.
1 parent 0a5864a commit 6bc4f14

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/packages/frontend/chat/chat-log.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export function ChatLog({
6868
costEstimate,
6969
}: Props) {
7070
const messages = useRedux(["messages"], project_id, path) as ChatMessages;
71-
7271
// see similar code in task list:
7372
const { selectedHashtags, selectedHashtagsSearch } = useMemo(() => {
7473
return getSelectedHashtagsSearch(selectedHashtags0);
@@ -507,7 +506,7 @@ export function MessageList({
507506
const virtuosoHeightsRef = useRef<{ [index: number]: number }>({});
508507
const virtuosoScroll = useVirtuosoScrollHook({
509508
cacheId: `${project_id}${path}`,
510-
initialState: { index: messages.size - 1, offset: 0 }, // starts scrolled to the newest message.
509+
initialState: { index: Math.max(sortedDates.length - 1, 0), offset: 0 }, // starts scrolled to the newest message.
511510
});
512511

513512
return (
@@ -528,8 +527,10 @@ export function MessageList({
528527
const date = sortedDates[index];
529528
const message: ChatMessageTyped | undefined = messages.get(date);
530529
if (message == null) {
531-
// shouldn't happen. But we should be robust to such a possibility.
532-
return <div style={{ height: "1px" }} />;
530+
// shouldn't happen, but make code robust to such a possibility.
531+
// if it happens, fix it.
532+
console.warn("empty message", { date, index, sortedDates });
533+
return <div style={{ height: "30px" }} />;
533534
}
534535

535536
// only do threading if numChildren is defined. It's not defined,

src/packages/frontend/chat/message.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ export default function Message({
401401
? { marginLeft: "5px", marginRight: "5px" }
402402
: undefined),
403403
...(selected ? { border: "3px solid #66bb6a" } : undefined),
404+
maxHeight: is_folded ? "100px" : undefined,
405+
overflowY: is_folded ? "auto" : undefined,
404406
} as const;
405407

406408
const mainXS = mode === "standalone" ? 20 : 22;
@@ -1006,7 +1008,9 @@ export default function Message({
10061008

10071009
function renderCols(): JSX.Element[] | JSX.Element {
10081010
// these columns should be filtered in the first place, this here is just an extra check
1009-
if (is_thread && is_folded && is_thread_body) return <></>;
1011+
if (is_thread && is_folded && is_thread_body) {
1012+
return <></>;
1013+
}
10101014

10111015
switch (mode) {
10121016
case "standalone":

0 commit comments

Comments
 (0)