Skip to content

Fix blog mermaid diagrams: blank-render race + mobile legibility#5283

Merged
liannacasper merged 1 commit into
masterfrom
fix-blog-mermaid-render-mobile
Jun 25, 2026
Merged

Fix blog mermaid diagrams: blank-render race + mobile legibility#5283
liannacasper merged 1 commit into
masterfrom
fix-blog-mermaid-render-mobile

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

Problem

Mermaid diagrams in the blog were broken in two ways (reported via java-to-a-native-linux-app):

  1. Diagrams sometimes render blank. The mermaid.html shortcode used startOnLoad: true. Mermaid v10's ESM build wires rendering to the window load event at import time, but the shortcode imports mermaid dynamically from a CDN — so the listener only catches load when the module happens to still be in-flight. On a cache hit, a bfcache restore, or a non-Chromium browser, load has already fired and the diagram silently stays blank.
  2. Wide diagrams are illegible on mobile. mermaid shrinks the wide flowchart LR diagrams to fit the viewport, collapsing them into an unreadable smudge on phones.

Fix

layouts/shortcodes/mermaid.html

  • startOnLoad: false + an explicit mermaid.run() — renders every .mermaid block regardless of load-event timing.
  • A one-time responsive <style> (overflow-x:auto, svg { max-width:100%; height:auto }) so a diagram never forces the page wider than the viewport.

Converted wide flowchart LRflowchart TD so nodes stack full-width and stay legible on phones:

  • developer-workflow-debug-and-junit.md (×2)
  • native-linux-apple-watch-game-builder-crash-protection.md
  • java-to-a-native-linux-app.md

The already-vertical TD chart (native-apple-watch-and-wear.md) and the sequenceDiagram (seamless-crash-protection.md) are unchanged.

Verification

Rebuilt with Hugo and rendered every diagram over HTTP (real theme) at 390px and 1100px:

  • All 6 diagrams render (data-processed=true), no syntax errors.
  • Zero page-level horizontal overflow at either width.
  • Converted flowcharts are full-width and legible on mobile (italics + edge labels intact).

Content/theme only — no Java or prose-gate surface touched.

🤖 Generated with Claude Code

The mermaid shortcode set startOnLoad:true, but mermaid v10's ESM build
wires rendering to window's "load" event at import time. Because the
shortcode imports mermaid dynamically from a CDN, that listener only fires
when the module is still in-flight at load -- on a cache hit, bfcache
restore, or non-Chromium browser the event has already fired and the
diagram silently stays blank.

Switch to startOnLoad:false + an explicit mermaid.run(), which renders
every .mermaid block regardless of load-event timing. Also inject a
one-time responsive style (overflow-x:auto, svg max-width:100%) so a
diagram never pushes the page wider than the viewport.

Separately, the wide "flowchart LR" diagrams shrank to an illegible smudge
on phones. Convert them to "flowchart TD" so each node is full-width and
readable on mobile: developer-workflow-debug-and-junit (x2),
native-linux-apple-watch-game-builder-crash-protection, and
java-to-a-native-linux-app. The already-vertical TD chart and the
sequence diagram are left unchanged.

Verified by rebuilding with Hugo and rendering every diagram over HTTP at
390px and 1100px: all render, no page overflow, legible on mobile.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Blog prose gate

✅ No net-new prose findings introduced by this PR.

@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@liannacasper liannacasper merged commit 9d5f5dc into master Jun 25, 2026
10 checks passed
@liannacasper liannacasper deleted the fix-blog-mermaid-render-mobile branch June 25, 2026 09:15
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.

2 participants