Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions frontend/app/[locale]/chat/streaming/chatStreamMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,46 @@ export function ChatStreamMain({
shouldScrollToBottom,
]);

// Additional scroll trigger for async content like Mermaid diagrams
useEffect(() => {
if (processedMessages.finalMessages.length > 0 && autoScroll) {
const scrollAreaElement = scrollAreaRef.current?.querySelector(
"[data-radix-scroll-area-viewport]"
);
if (!scrollAreaElement) return;

// Use ResizeObserver to detect when content height changes (e.g., Mermaid diagrams finish rendering)
const resizeObserver = new ResizeObserver(() => {
const { scrollTop, scrollHeight, clientHeight } =
scrollAreaElement as HTMLElement;
const distanceToBottom = scrollHeight - scrollTop - clientHeight;

// Auto-scroll if user is near bottom and content height changed
if (distanceToBottom < 100) {
scrollToBottom();
}
});

resizeObserver.observe(scrollAreaElement);

// Also use a timeout as fallback for async content
const timeoutId = setTimeout(() => {
const { scrollTop, scrollHeight, clientHeight } =
scrollAreaElement as HTMLElement;
const distanceToBottom = scrollHeight - scrollTop - clientHeight;

if (distanceToBottom < 100) {
scrollToBottom();
}
}, 1000); // Wait 1 second for async content to render

return () => {
resizeObserver.disconnect();
clearTimeout(timeoutId);
};
}
}, [processedMessages.finalMessages.length, autoScroll]);

// Scroll to bottom when task messages are updated
useEffect(() => {
if (autoScroll) {
Expand Down
41 changes: 37 additions & 4 deletions frontend/app/[locale]/chat/streaming/taskWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ const messageHandlers: MessageHandler[] = [
<MarkdownRenderer
content={message.content}
className="task-message-content"
showDiagramToggle={false}
/>
</div>
),
Expand Down Expand Up @@ -757,6 +758,7 @@ const messageHandlers: MessageHandler[] = [
<MarkdownRenderer
content={content}
className="task-message-content"
showDiagramToggle={false}
/>
);
} else {
Expand Down Expand Up @@ -1061,7 +1063,8 @@ export function TaskWindow({ messages, isStreaming = false }: TaskWindowProps) {
const maxHeight = 300;
const headerHeight = 55;
const availableHeight = maxHeight - headerHeight;
const actualContentHeight = Math.min(contentHeight + 16, availableHeight);
// Add extra padding for diagrams to prevent bottom cutoff
const actualContentHeight = Math.min(contentHeight + 32, availableHeight);
const containerHeight = isExpanded
? headerHeight + actualContentHeight
: "auto";
Expand Down Expand Up @@ -1096,15 +1099,15 @@ export function TaskWindow({ messages, isStreaming = false }: TaskWindowProps) {
</div>

{isExpanded && (
<div className="px-4" style={{ height: `${actualContentHeight}px` }}>
<div className="px-4 pb-4" style={{ height: `${actualContentHeight}px` }}>
{needsScroll ? (
<ScrollArea className="h-full" ref={scrollAreaRef}>
<div className="" ref={contentRef}>
<div className="pb-2" ref={contentRef}>
{renderMessages()}
</div>
</ScrollArea>
) : (
<div className="" ref={contentRef}>
<div className="pb-2" ref={contentRef}>
{renderMessages()}
</div>
)}
Expand Down Expand Up @@ -1183,6 +1186,36 @@ export function TaskWindow({ messages, isStreaming = false }: TaskWindowProps) {
box-sizing: border-box !important;
}

/* Override diagram size in task window */
.task-message-content .my-4 {
max-width: 200px !important;
margin: 0 auto !important;
display: flex !important;
justify-content: center !important;
}

.task-message-content .my-4 img {
max-width: 200px !important;
width: 200px !important;
margin: 0 auto !important;
display: block !important;
}

/* More specific selectors for mermaid diagrams */
.task-message-content .task-message-content .my-4 {
max-width: 200px !important;
margin: 0 auto !important;
display: flex !important;
justify-content: center !important;
}

.task-message-content .task-message-content .my-4 img {
max-width: 200px !important;
width: 200px !important;
margin: 0 auto !important;
display: block !important;
}

/* Paragraph spacing adjustment */
.task-message-content p {
margin-bottom: 0.5rem !important;
Expand Down
Loading