From 613dcd8c9b5fb28a95d34df8e97367a9471f5492 Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Fri, 17 Jul 2026 16:39:02 -0700 Subject: [PATCH] fix(pr-comments): make the review sidebar legible for structured bot markdown (#9209) Restore readable block flow, typography, nested spacing, and heading semantics for structured review Markdown in the PR sidebar. Preserve the compact renderer's existing remote-image trust boundary. --- .../pr-comment-presentation.test.ts | 72 +++++++++++++++++-- .../right-sidebar/pr-comment-presentation.ts | 37 ++++++++-- .../sidebar/CommentMarkdown.test.tsx | 27 +++++++ .../comment-markdown-element-renderers.tsx | 40 ++++++++--- 4 files changed, 158 insertions(+), 18 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts b/src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts index b85c7085d..388ad914d 100644 --- a/src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts +++ b/src/renderer/src/components/right-sidebar/pr-comment-presentation.test.ts @@ -15,8 +15,8 @@ describe('pr-comment-presentation', () => { it('returns card layout tokens for cards and focus variants', () => { const cards = getPRCommentPresentationClasses('cards') expect(cards.useCardLayout).toBe(true) - expect(cards.commentBody).toContain('text-xs') - expect(cards.commentBody).toContain('leading-5') + expect(cards.commentBody).toContain('text-[13px]') + expect(cards.commentBody).toContain('leading-relaxed') expect(cards.commentBody).toContain('text-foreground') expect(cards.group).toContain('bg-secondary') expect(cards.group).toContain('shadow-xs') @@ -25,10 +25,10 @@ describe('pr-comment-presentation', () => { const focus = getPRCommentPresentationClasses('focus') expect(focus.useCardLayout).toBe(true) - expect(focus.commentBody).toContain('text-xs') - expect(focus.commentBody).toContain('leading-5') - expect(focus.commentBodyReply).toContain('text-xs') - expect(focus.commentBodyReply).toContain('leading-5') + expect(focus.commentBody).toContain('text-[13px]') + expect(focus.commentBody).toContain('leading-relaxed') + expect(focus.commentBodyReply).toContain('text-[13px]') + expect(focus.commentBodyReply).toContain('leading-relaxed') expect(focus.author).toContain('text-[13px]') expect(focus.list).toContain('gap-2') expect(focus.commentBody).toContain('px-4 py-2.5') @@ -39,6 +39,66 @@ describe('pr-comment-presentation', () => { expect(focus.commentHeaderMetaWithSelection).toContain('pl-[3.25rem]') }) + it('restores block flow for span-rendered markdown paragraphs and headings', () => { + for (const variant of ['cards', 'focus', 'flat'] as const) { + const markdown = getPRCommentPresentationClasses(variant).commentBodyMarkdown + // The compact renderer emits no

, so a [&_p] rule would be dead code. + expect(markdown).not.toContain('[&_p]:') + expect(markdown).toContain('[&_.comment-md-p]:block') + expect(markdown).toContain('[&_.comment-md-p+.comment-md-p]:mt-2') + // Rhythm must key off every top-level block: a

/
between two + // paragraphs breaks an adjacent-sibling chain and zeroes the tail spacing. + expect(markdown).toContain('[&>*+*]:mt-2') + expect(markdown).toContain('[&_details]:my-2') + expect(markdown).toContain('[&_.comment-md-h]:block') + expect(markdown).toContain('[&_.comment-md-h]:mt-4') + } + }) + + it('lifts code, pre, and table off the 10px compact defaults', () => { + const markdown = getPRCommentPresentationClasses('cards').commentBodyMarkdown + expect(markdown).toContain('[&_code]:text-[0.92em]') + expect(markdown).toContain('[&_pre]:text-xs') + // Code inside a fence must track the fence, not shrink again. + expect(markdown).toContain('[&_pre_code]:text-[1em]') + expect(markdown).toContain('[&_table]:text-[12px]') + }) + + it('stops sub/sup small-print from compounding below the caption tier', () => { + const markdown = getPRCommentPresentationClasses('cards').commentBodyMarkdown + // The browser's 75% nests: 13px -> 9.75px -> 7.3px. Absolute sizes don't compound. + expect(markdown).toContain('[&_sub]:text-[11px]') + expect(markdown).toContain('[&_sup]:text-[11px]') + }) + + it('neutralizes the baseline sag only for sub/sup wrapping a badge image', () => { + const markdown = getPRCommentPresentationClasses('cards').commentBodyMarkdown + // stacks two -0.25em shifts; text subscripts keep theirs. + expect(markdown).toContain('[&_sub:has(img)]:bottom-0') + expect(markdown).toContain('[&_sub:has(img)]:align-middle') + expect(markdown).not.toContain('[&_sub]:bottom-0') + }) + + it('gives headings a perceptible step over the 13px body', () => { + const markdown = getPRCommentPresentationClasses('cards').commentBodyMarkdown + // 13px headings over a 12px body was a 1.08x ratio — invisible. Match the + // document variant's scale instead. + expect(markdown).toContain('[&_.comment-md-h1]:text-[18px]') + expect(markdown).toContain('[&_.comment-md-h2]:text-[16px]') + expect(markdown).toContain('[&_.comment-md-h3]:text-[15px]') + expect(markdown).not.toContain('[&_.comment-md-h1]:text-[13px]') + }) + + it('promotes bold-then-linebreak labels but not mid-sentence emphasis', () => { + const markdown = getPRCommentPresentationClasses('cards').commentBodyMarkdown + const label = '[&_.comment-md-p>strong:first-child:has(+br)' + expect(markdown).toContain(`${label}]:text-[15px]`) + expect(markdown).toContain(`${label}]:block`) + expect(markdown).toContain('[&_.comment-md-p:first-child>strong:first-child:has(+br)]:mt-0') + // Blocking the label makes its own
a duplicate break. + expect(markdown).toContain(`${label}+br]:hidden`) + }) + it('preserves the legacy flat layout tokens', () => { const flat = getPRCommentPresentationClasses('flat') expect(flat.useCardLayout).toBe(false) diff --git a/src/renderer/src/components/right-sidebar/pr-comment-presentation.ts b/src/renderer/src/components/right-sidebar/pr-comment-presentation.ts index 6ce3560f6..aa754f61e 100644 --- a/src/renderer/src/components/right-sidebar/pr-comment-presentation.ts +++ b/src/renderer/src/components/right-sidebar/pr-comment-presentation.ts @@ -72,8 +72,36 @@ export function getPRCommentGroupSurfaceClasses( return classes.join(' ') } -const MARKDOWN_BASE = - 'break-words [&_p]:my-1.5 [&_pre]:max-h-none [&_pre]:max-w-full [&_pre]:whitespace-pre-wrap [&_table]:w-full [&_table]:max-w-full' +// Why: compact p/h spans weld onto one line; scope block flow here so the +// renderer's other consumers retain their dense layout. +const MARKDOWN_BASE = cn( + 'break-words', + // Why: rhythm keys off every top-level block, not adjacent paragraphs — a
or + // raw
between them otherwise breaks the chain and collapses the tail to zero gap. + '[&_.comment-md-p]:block [&_.comment-md-p+.comment-md-p]:mt-2 [&>*+*]:mt-2 [&_details]:my-2', + '[&_.comment-md-h]:mt-4 [&_.comment-md-h]:mb-1 [&_.comment-md-h]:block [&_.comment-md-h]:leading-tight [&_.comment-md-h:first-child]:mt-0', + // Why: the document variant's proven scale (18/16/15 over 13px body) — the sidebar was + // the only surface rendering this markdown with no perceptible heading step. + '[&_.comment-md-h1]:text-[18px] [&_.comment-md-h2]:text-[16px] [&_.comment-md-h3]:text-[15px]', + // Why: bots write section titles as bold-then-linebreak, not headings, so those carry + // the real hierarchy. :has(+br) promotes only those, never mid-sentence emphasis. + '[&_.comment-md-p>strong:first-child:has(+br)]:mt-3 [&_.comment-md-p>strong:first-child:has(+br)]:mb-0.5 [&_.comment-md-p>strong:first-child:has(+br)]:block [&_.comment-md-p>strong:first-child:has(+br)]:text-[15px] [&_.comment-md-p>strong:first-child:has(+br)]:leading-tight', + '[&_.comment-md-p:first-child>strong:first-child:has(+br)]:mt-0', + // The label's own
would double the break once it is block-level. + '[&_.comment-md-p>strong:first-child:has(+br)+br]:hidden', + // Why: compact sizes code/pre/tables at 10px inside the prose, shrinking the densest + // content. 0.92em mirrors the document variant's inline-code ratio. + '[&_code]:text-[0.92em] [&_pre]:text-xs [&_pre_code]:text-[1em] [&_table]:text-[12px]', + // Why: bots use sub/sup as small-print, and the browser's 75% compounds when nested + // (13px -> 7.3px). An absolute size stops the compounding at the caption tier. + '[&_sub]:text-[11px] [&_sup]:text-[11px]', + // Why: a badge wrapped in inherits both -0.25em shifts (5.5px of sag). + // Only neutralize wrappers holding an image; real text subscripts keep their offset. + '[&_sub:has(img)]:bottom-0 [&_sub:has(img)]:align-middle', + '[&_sup:has(img)]:top-0 [&_sup:has(img)]:align-middle', + '[&_pre]:max-h-none [&_pre]:max-w-full [&_pre]:whitespace-pre-wrap', + '[&_table]:w-full [&_table]:max-w-full' +) // Why: in light mode card and canvas are both #fff, so border-border alone disappears. // overflow-clip preserves rounded clipping without letting focused row actions scroll content. @@ -89,8 +117,9 @@ const COMMENT_AVATAR = const RESOLVED_SECTION_LABEL = 'text-[11px] font-semibold uppercase tracking-wider text-muted-foreground' -// Why: markdown bodies need the secondary sidebar scale; 13px relaxed copy reads oversized in narrow comment cards. -const CARD_COMMENT_BODY_SIZE = 'text-xs leading-5' +// Why: matches the document-variant body (PullRequestPage/GitHubItemDialog) so the same +// bot markdown reads the same everywhere; 12px left no room for a heading step above it. +const CARD_COMMENT_BODY_SIZE = 'text-[13px] leading-relaxed' const CARD_COMMENT_AUTHOR_SIZE = 'text-[13px]' const CARD_COMMENT_LIST_GAP = 'gap-2' const CARD_COMMENT_BODY_PADDING = 'px-4 py-2.5' diff --git a/src/renderer/src/components/sidebar/CommentMarkdown.test.tsx b/src/renderer/src/components/sidebar/CommentMarkdown.test.tsx index b64d10a04..4ca6323a8 100644 --- a/src/renderer/src/components/sidebar/CommentMarkdown.test.tsx +++ b/src/renderer/src/components/sidebar/CommentMarkdown.test.tsx @@ -3,6 +3,33 @@ import { describe, expect, it } from 'vitest' import CommentMarkdown, { remarkGitHubReferences } from './CommentMarkdown' describe('CommentMarkdown', () => { + it('marks compact headings so a parent can opt into block flow', () => { + const markup = renderToStaticMarkup( + + ) + + expect(markup).toContain('comment-md-h comment-md-h2') + expect(markup).toContain('comment-md-p') + expect(markup).toContain('role="heading"') + expect(markup).toContain('aria-level="2"') + // Weight-only styling stays the compact default; block flow is opt-in. + expect(markup).toContain('font-bold') + }) + + it('marks adjacent compact paragraphs inside disclosure content', () => { + const markup = renderToStaticMarkup( + More\n\nFirst paragraph.\n\nSecond paragraph.\n\n
' + } + /> + ) + + expect(markup).toContain( + 'First paragraph.\nSecond paragraph.' + ) + }) + it('autolinks same-repo GitHub issue references when repo context is provided', () => { const markup = renderToStaticMarkup( (
  • {children}
  • ), - // Headings render as bold text at the same size — no visual hierarchy needed - // in a tiny sidebar card. - h1: ({ children }) => {children}, - h2: ({ children }) => {children}, - h3: ({ children }) => {children}, - h4: ({ children }) => {children}, - h5: ({ children }) => {children}, - h6: ({ children }) => {children}, + // Spans preserve compact flow on shared surfaces; roles keep the source + // heading hierarchy navigable when the PR sidebar promotes them visually. + h1: ({ children }) => ( + + {children} + + ), + h2: ({ children }) => ( + + {children} + + ), + h3: ({ children }) => ( + + {children} + + ), + h4: ({ children }) => ( + + {children} + + ), + h5: ({ children }) => ( + + {children} + + ), + h6: ({ children }) => ( + + {children} + + ), // Horizontal rules as a subtle divider hr: () =>
    , // Compact blockquotes