Skip to content

fix: scale wide Mermaid diagrams to fit the column (stop sidebar overlap)#878

Merged
yuanhao merged 2 commits into
mainfrom
fix-mermaid-overflow
Jul 8, 2026
Merged

fix: scale wide Mermaid diagrams to fit the column (stop sidebar overlap)#878
yuanhao merged 2 commits into
mainfrom
fix-mermaid-overflow

Conversation

@yuanhao

@yuanhao yuanhao commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

On recursive-self-improvement-rsi the RSI flowchart renders far wider than the article column and spills across the "On this page" sidebar — nodes like Improve? / Keep Current land on top of the TOC.

Cause

The Mermaid renderer (beautiful-mermaid) bakes a hard pixel width into the SVG (width="1204" for this chart) alongside its viewBox. The <div class="mermaid-diagram"> replaces <pre>, so .prose-article > * capped the div at the 66ch reading measure — but nothing constrained the SVG inside it, which rendered at its full 1204px intrinsic width and overflowed.

Fix (CSS only)

  • Add .mermaid-diagram to the full-column media list (img, figure, pre, table, hr) so a diagram gets the whole column instead of 66ch.
  • Clamp the SVG: max-width:100%; height:auto. Because the SVG has a viewBox, this scales the whole diagram down proportionally to fit the column (CSS max-width overrides the presentation width attribute; height:auto recomputes from the viewBox ratio). Same responsive pattern the <img> handler already uses (MarkdownRenderer.tsx:189). overflow-x:auto is a safety net.

No content change — fixes every wide diagram site-wide, not just this page.

Test

  • pnpm build green. CSS-only; no logic/tests affected.
  • Behavior is spec-guaranteed for viewBox SVGs; verified the SVG carries viewBox="0 0 1204.396 200.784" + hard width/height.

🤖 Generated with Claude Code

yuanhao and others added 2 commits July 8, 2026 17:15
…lap)

The Mermaid renderer bakes a hard pixel width/height into the SVG (e.g.
width="1204"), so a wide LR flowchart overflowed the article column and
spilled across the "On this page" sidebar (see recursive-self-improvement-rsi).
The <div class="mermaid-diagram"> replaces <pre>, so it was capped at the
66ch reading measure while the SVG inside it rendered at its full intrinsic
width with nothing clamping it.

Fix (CSS only):
- add .mermaid-diagram to the full-column media list (like img/figure/pre/
  table) so the diagram gets the whole column instead of 66ch.
- clamp the SVG: max-width:100%; height:auto. The SVG carries a viewBox, so
  this scales the whole diagram down proportionally to fit — the same
  responsive pattern the <img> handler already uses. overflow-x:auto is a
  safety net.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review nit: max-width:100% on the SVG already prevents horizontal overflow,
so overflow-x:auto never actually scrolls — reword so the comment doesn't
overclaim it as a safety net.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yuanhao yuanhao merged commit 2e8842c into main Jul 8, 2026
1 check passed
@yuanhao yuanhao deleted the fix-mermaid-overflow branch July 8, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant