Skip to content

Commit 4299961

Browse files
authored
Merge pull request #191 from AGiXT/Fix-side-scrolling-in-chat
Fix side scrolling in chat
2 parents 1443e37 + a9a04cc commit 4299961

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

app/globals.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ img[src=""],img[src="#"] {
159159
.katex-display {
160160
@apply my-4 overflow-x-auto;
161161
max-width: 100%;
162+
box-sizing: border-box;
163+
}
164+
165+
.katex {
166+
max-width: 100%;
167+
overflow-x: auto;
168+
overflow-y: hidden;
162169
}
163170

164171
.dark .katex {
@@ -168,3 +175,38 @@ img[src=""],img[src="#"] {
168175
.dark .katex-html {
169176
color: var(--foreground);
170177
}
178+
179+
/* Prevent horizontal overflow for all content */
180+
.code-container,
181+
.data-table,
182+
.markdown-content,
183+
pre,
184+
code {
185+
max-width: 100%;
186+
box-sizing: border-box;
187+
word-wrap: break-word;
188+
overflow-wrap: break-word;
189+
}
190+
191+
/* Ensure tables are responsive */
192+
table {
193+
max-width: 100%;
194+
overflow-x: auto;
195+
display: block;
196+
white-space: nowrap;
197+
}
198+
199+
/* For very long words or URLs */
200+
.message-content {
201+
word-break: break-word;
202+
overflow-wrap: break-word;
203+
hyphens: auto;
204+
}
205+
206+
/* Prevent pre elements from causing overflow */
207+
pre {
208+
white-space: pre-wrap;
209+
word-wrap: break-word;
210+
overflow-x: auto;
211+
max-width: 100%;
212+
}

components/conversation/Message/Markdown/CodeBlock.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export default function CodeBlock({
205205
<Collapsible
206206
open={isOpen}
207207
onOpenChange={setIsOpen}
208-
className={`my-2 overflow-hidden border rounded-lg bg-card transition-all duration-300 ease-in-out ${isOpen ? 'w-full' : 'inline-block'}`}
208+
className={`my-2 overflow-hidden border rounded-lg bg-card transition-all duration-300 ease-in-out max-w-full ${isOpen ? 'w-full' : 'inline-block'}`}
209209
>
210210
<div className='relative flex items-center justify-between pr-4 border-b-2 border-border'>
211211
<CollapsibleTrigger className='p-2 hover:bg-muted'>
@@ -248,7 +248,7 @@ export default function CodeBlock({
248248
)}
249249

250250
<TabPanel value={tab} index={hasCustomRenderer ? 1 : 0}>
251-
<div className='code-container bg-card p-4' ref={codeBlockRef}>
251+
<div className='code-container bg-card p-4 overflow-x-auto max-w-full' ref={codeBlockRef}>
252252
{languageKey in fileExtensions ? (
253253
<SyntaxHighlighter
254254
{...props}

components/conversation/Message/MarkdownBlock.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function MarkdownBlock({ content, chatItem, setLoading }: Markdow
6565
}
6666
try {
6767
return (
68-
<>
68+
<div className='message-content'>
6969
{textToMarkdown(content.toString()).map((segment, index) => {
7070
if (segment.type === undefined) {
7171
return (
@@ -110,7 +110,7 @@ export default function MarkdownBlock({ content, chatItem, setLoading }: Markdow
110110
table() {
111111
const { columns, rows } = parseMarkdownTable(segment.content);
112112
return (
113-
<div className='w-full'>
113+
<div className='w-full overflow-x-auto'>
114114
<DataTable columns={createColumns(columns)} data={rows} />
115115
</div>
116116
);
@@ -144,7 +144,7 @@ export default function MarkdownBlock({ content, chatItem, setLoading }: Markdow
144144
);
145145
}
146146
})}
147-
</>
147+
</div>
148148
);
149149
} catch (e) {
150150
console.error(e);

components/conversation/Message/Message.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ export default function Message({ chatItem, lastUserMessage, setLoading }: Messa
9393
const isUserMsgJustText = checkUserMsgJustText(chatItem);
9494

9595
return (
96-
<div className={cn('m-3 overflow-hidden flex flex-col gap-2 min-w-48', isUserMsgJustText && 'max-w-[60%] self-end')}>
96+
<div
97+
className={cn(
98+
'm-3 overflow-hidden flex flex-col gap-2 min-w-0 max-w-full',
99+
isUserMsgJustText && 'max-w-[60%] self-end',
100+
)}
101+
>
97102
{audios && audios.sources.length > 0 ? (
98103
<>
99104
{audios.message?.trim() && (
@@ -111,8 +116,8 @@ export default function Message({ chatItem, lastUserMessage, setLoading }: Messa
111116
<div
112117
className={
113118
chatItem.role === 'USER'
114-
? 'chat-log-message-user bg-primary rounded-3xl py-1 rounded-br-none px-5 text-primary-foreground'
115-
: 'chat-log-message-ai p-0 pt-2 text-foreground'
119+
? 'chat-log-message-user bg-primary rounded-3xl py-1 rounded-br-none px-5 text-primary-foreground overflow-hidden'
120+
: 'chat-log-message-ai p-0 pt-2 text-foreground overflow-hidden'
116121
}
117122
>
118123
<MarkdownBlock content={formattedMessage} chatItem={chatItem} setLoading={setLoading} />

components/conversation/Message/data-table/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export function DataTable<TData, TValue>({ columns, data }: DataTableProps<TData
5454
});
5555

5656
return (
57-
<div className='w-full p-2 space-y-2 rounded-md bg-background text-foreground'>
57+
<div className='w-full p-2 space-y-2 rounded-md bg-background text-foreground max-w-full'>
5858
<DataTableToolbar table={table} />
59-
<div className='border rounded-md'>
60-
<Table>
59+
<div className='border rounded-md overflow-x-auto'>
60+
<Table className='min-w-full'>
6161
<TableHeader className='font-bold bg-muted/50 text-foreground'>
6262
{table.getHeaderGroups().map((headerGroup) => (
6363
<TableRow key={headerGroup.id}>

components/conversation/conversation.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,11 @@ export function ChatLog({
360360
}, [conversation]);
361361

362362
return (
363-
<div className='flex flex-col-reverse flex-grow overflow-auto bg-background pb-28' style={{ flexBasis: '0px' }}>
364-
<div className='flex flex-col h-min'>
363+
<div
364+
className='flex flex-col-reverse flex-grow overflow-y-auto overflow-x-hidden bg-background pb-28'
365+
style={{ flexBasis: '0px' }}
366+
>
367+
<div className='flex flex-col h-min min-w-0'>
365368
{conversation && conversation.length > 0 ? (
366369
conversation
367370
.filter((chatItem) => {

0 commit comments

Comments
 (0)