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.
This commit is contained in:
@@ -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 <p>, 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 <details>/<div> 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
|
||||
// <sub><sub><img></sub></sub> 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 <br> 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)
|
||||
|
||||
@@ -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 <details> or
|
||||
// raw <div> 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 <br> 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 <sub><sub> 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'
|
||||
|
||||
@@ -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(
|
||||
<CommentMarkdown content={'## Walkthrough\n\nAdds verify:changed, which collects.'} />
|
||||
)
|
||||
|
||||
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(
|
||||
<CommentMarkdown
|
||||
content={
|
||||
'<details><summary>More</summary>\n\nFirst paragraph.\n\nSecond paragraph.\n\n</details>'
|
||||
}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(markup).toContain(
|
||||
'<span class="comment-md-p">First paragraph.</span>\n<span class="comment-md-p">Second paragraph.</span>'
|
||||
)
|
||||
})
|
||||
|
||||
it('autolinks same-repo GitHub issue references when repo context is provided', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<CommentMarkdown
|
||||
|
||||
@@ -97,14 +97,38 @@ export function createCompactCommentMarkdownComponents(
|
||||
li: ({ children }) => (
|
||||
<li className="leading-normal [&>input]:pointer-events-none">{children}</li>
|
||||
),
|
||||
// Headings render as bold text at the same size — no visual hierarchy needed
|
||||
// in a tiny sidebar card.
|
||||
h1: ({ children }) => <span className="font-bold">{children}</span>,
|
||||
h2: ({ children }) => <span className="font-bold">{children}</span>,
|
||||
h3: ({ children }) => <span className="font-semibold">{children}</span>,
|
||||
h4: ({ children }) => <span className="font-semibold">{children}</span>,
|
||||
h5: ({ children }) => <span className="font-semibold">{children}</span>,
|
||||
h6: ({ children }) => <span className="font-semibold">{children}</span>,
|
||||
// Spans preserve compact flow on shared surfaces; roles keep the source
|
||||
// heading hierarchy navigable when the PR sidebar promotes them visually.
|
||||
h1: ({ children }) => (
|
||||
<span className="comment-md-h comment-md-h1 font-bold" role="heading" aria-level={1}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
h2: ({ children }) => (
|
||||
<span className="comment-md-h comment-md-h2 font-bold" role="heading" aria-level={2}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
h3: ({ children }) => (
|
||||
<span className="comment-md-h comment-md-h3 font-semibold" role="heading" aria-level={3}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
h4: ({ children }) => (
|
||||
<span className="comment-md-h font-semibold" role="heading" aria-level={4}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
h5: ({ children }) => (
|
||||
<span className="comment-md-h font-semibold" role="heading" aria-level={5}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
h6: ({ children }) => (
|
||||
<span className="comment-md-h font-semibold" role="heading" aria-level={6}>
|
||||
{children}
|
||||
</span>
|
||||
),
|
||||
// Horizontal rules as a subtle divider
|
||||
hr: () => <hr className="my-1 border-border/50" />,
|
||||
// Compact blockquotes
|
||||
|
||||
Reference in New Issue
Block a user