The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a wide code block in a native chat scrolls as on main
emozillacce9f40c6704
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.overflow.test.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.overflow.test.tsxindex 9c862a30bf0..58e1558e29d 100644--- a/apps/desktop/src/components/assistant-ui/markdown-text.overflow.test.tsx+++ b/apps/desktop/src/components/assistant-ui/markdown-text.overflow.test.tsx@@ -82,36 +82,61 @@ describe('MarkdownTextContent overflow containment', () => {// and scroll inside their own cards, so the thread itself stays one column// wide. The missing link was min-w-0 on the markdown container.it('keeps prose in the column while tables and code scroll inside their own cards', async () => {- const longToken = 'x'.repeat(500)-- const text = [- longToken,- '',- '```text',- longToken,- '```',- '',- '| Header with a long value | Other |',- '| --- | --- |',- `| ${longToken} | value |`- ].join('\n')-- const { container } = render(<MarkdownTextContent isRunning={false} text={text} />)-- await waitFor(() => expect(container.querySelector('[data-slot="code-card"]')).toBeTruthy())-- const markdown = container.querySelector('.aui-md')!- const codeCard = container.querySelector('[data-slot="code-card"]')!- // The card's overlay scroller (ExpandableBlock's inner div).- const codeScroller = codeCard.querySelector('.scrollbar-overlay')!- // The fence's own <pre> takes its longest line's width, so the scroller above scrolls it.- const fencePre = codeScroller.querySelector('pre')!- const tableWrapper = container.querySelector('.aui-md-table')!+ const { codeCard, codeScroller, fencePre, longToken, markdown, tableWrapper } = await renderWideReply()expect(markdown.className).toContain('min-w-0')expect(codeScroller.className).toContain('overflow-x-auto')- expect(fencePre.className).toContain('min-w-max')+ // Native Desktop: the fence's <pre> keeps the card's width and scrolls its+ // long lines itself, as on main.+ expect(fencePre.className).not.toContain('min-w-max')expect(codeCard.textContent).toContain(longToken)expect(tableWrapper.className).toContain('overflow-x-auto')})++ // The browser host sizes the fence's <pre> to its longest line, so the card's+ // scroller scrolls it sideways in place and draws the fade at the cut edge.+ it('sizes the fence to its longest line in browser-hosted Desktop', async () => {+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'++ try {+ const { fencePre } = await renderWideReply()++ expect(fencePre.className).toContain('min-w-max')+ } finally {+ delete window.document.documentElement.dataset.hermesDesktopHost+ }+ })})++async function renderWideReply() {+ const longToken = 'x'.repeat(500)++ const text = [+ longToken,+ '',+ '```text',+ longToken,+ '```',+ '',+ '| Header with a long value | Other |',+ '| --- | --- |',+ `| ${longToken} | value |`+ ].join('\n')++ const { container } = render(<MarkdownTextContent isRunning={false} text={text} />)++ await waitFor(() => expect(container.querySelector('[data-slot="code-card"]')).toBeTruthy())++ const codeCard = container.querySelector('[data-slot="code-card"]')!+ // The card's overlay scroller (ExpandableBlock's inner div).+ const codeScroller = codeCard.querySelector('.scrollbar-overlay')!++ return {+ codeCard,+ codeScroller,+ fencePre: codeScroller.querySelector('pre')!,+ longToken,+ markdown: container.querySelector('.aui-md')!,+ tableWrapper: container.querySelector('.aui-md-table')!+ }+}diff --git a/apps/desktop/src/components/chat/expandable-block.test.tsx b/apps/desktop/src/components/chat/expandable-block.test.tsxindex 371c788aeb0..fd8fddaead0 100644--- a/apps/desktop/src/components/chat/expandable-block.test.tsx+++ b/apps/desktop/src/components/chat/expandable-block.test.tsx@@ -24,6 +24,7 @@ class TestResizeObserver {afterEach(() => {cleanup()vi.unstubAllGlobals()+ delete window.document.documentElement.dataset.hermesDesktopHost})describe('ExpandableBlock', () => {@@ -45,6 +46,7 @@ describe('ExpandableBlock', () => {})it('shows a non-blocking horizontal cue until a wide block reaches its end', () => {+ window.document.documentElement.dataset.hermesDesktopHost = 'browser'vi.stubGlobal('ResizeObserver', TestResizeObserver)render(@@ -71,4 +73,20 @@ describe('ExpandableBlock', () => {.parentElement?.parentElement?.querySelector('[data-slot="expandable-horizontal-fade"]')).toBeNull()})++ // Native Desktop draws no sideways cue on a wide block, as on main.+ it('draws no horizontal cue on a wide block in native Desktop', () => {+ vi.stubGlobal('ResizeObserver', TestResizeObserver)++ render(+ <ExpandableBlock>+ <pre data-testid="content">{'wide line\n'.repeat(2)}</pre>+ </ExpandableBlock>+ )++ const block = screen.getByTestId('content').parentElement!++ expect(block.hasAttribute('data-horizontal-overflow')).toBe(false)+ expect(block.parentElement?.querySelector('[data-slot="expandable-horizontal-fade"]')).toBeNull()+ })})diff --git a/apps/desktop/src/components/chat/expandable-block.tsx b/apps/desktop/src/components/chat/expandable-block.tsxindex 89a1474dc35..3245398b574 100644--- a/apps/desktop/src/components/chat/expandable-block.tsx+++ b/apps/desktop/src/components/chat/expandable-block.tsx@@ -4,6 +4,7 @@ import { type ReactNode, useCallback, useRef, useState } from 'react'import { useResizeObserver } from '@/hooks/use-resize-observer'import { ChevronDown } from '@/lib/icons'+import { isBrowserHostedDesktop } from '@/lib/platform'import { cn } from '@/lib/utils'interface ExpandableBlockProps {@@ -26,7 +27,10 @@ export function ExpandableBlock({ children, className }: ExpandableBlockProps) {if (el) {setOverflowing(el.scrollHeight > 121)- const hasHorizontalOverflow = el.scrollWidth > el.clientWidth + 1+ // The sideways cue belongs to the browser host, whose code fences are+ // sized to their longest line (shiki-highlighter.tsx) and whose touch+ // screens show no scrollbar. Native Desktop keeps main's block.+ const hasHorizontalOverflow = isBrowserHostedDesktop() && el.scrollWidth > el.clientWidth + 1setHorizontalOverflowing(hasHorizontalOverflow)setHorizontalAtEnd(!hasHorizontalOverflow || el.scrollLeft + el.clientWidth >= el.scrollWidth - 1)diff --git a/apps/desktop/src/components/chat/shiki-highlighter.tsx b/apps/desktop/src/components/chat/shiki-highlighter.tsxindex acaa4b32216..d0fdbdbefa4 100644--- a/apps/desktop/src/components/chat/shiki-highlighter.tsx+++ b/apps/desktop/src/components/chat/shiki-highlighter.tsx@@ -13,6 +13,7 @@ import { SHIKI_COLOR_REPLACEMENTS } from '@/components/chat/shiki-config'import { CopyButton } from '@/components/ui/copy-button'import { useI18n } from '@/i18n'import { isLikelyProseCodeBlock } from '@/lib/markdown-code'+import { isBrowserHostedDesktop } from '@/lib/platform'import type { CachedShikiBlockProps } from './shiki-block'import { isChunkLoadError, ShikiChunkBoundary } from './shiki-chunk-boundary'@@ -198,8 +199,16 @@ export const SyntaxHighlighter: FC<HermesSyntaxHighlighterProps> = ({/><CodeCardBody className="[&_pre]:px-3 [&_pre]:py-2.5"><ExpandableBlock>- {/* Sized to the longest line, so ExpandableBlock scrolls it sideways and draws its fade. */}- <Pre className="aui-shiki m-0 min-w-max bg-transparent p-0">+ {/* In the browser host the fence is sized to its longest line, so+ ExpandableBlock scrolls it sideways in place and draws its fade.+ Native Desktop keeps main's fence, whose <pre> scrolls itself. */}+ <Pre+ className={+ isBrowserHostedDesktop()+ ? 'aui-shiki m-0 min-w-max bg-transparent p-0'+ : 'aui-shiki m-0 overflow-hidden bg-transparent p-0'+ }+ >{plain ? (<PlainCode code={content} />) : (