Skip to content

feat(site): mermaid diagram rendering + real footnotes in the cross-build matrix#487

Merged
Brooooooklyn merged 3 commits into
mainfrom
mermaid-and-footnotes
Jul 7, 2026
Merged

feat(site): mermaid diagram rendering + real footnotes in the cross-build matrix#487
Brooooooklyn merged 3 commits into
mainfrom
mermaid-and-footnotes

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Follow-up to #486, fixing two rendering gaps it exposed:

Mermaid diagrams

The site never rendered ```mermaid fences — @void/md has no mermaid support, so the cross-build decision tree (and the pre-existing diagrams on understanding-lifetime) displayed as raw code.

  • New MermaidBlocks docs island (with { island: 'load' } in the en/cn/pt-BR docs layouts): SSR keeps the code fence as fallback; on pages that contain mermaid fences it lazy-imports mermaid, renders each fence to SVG, and hides the fence.
  • Theme-aware: re-renders on html[data-theme] toggle (MutationObserver).
  • Idempotent across remounts (adopts existing host, full cleanup restores the fence) and fails back to the visible code fence if a render throws — per-block, without affecting sibling diagrams.
  • Pages without diagrams pay 1.2 KB gzip (the island only); diagram pages lazily pull ~194 KB gzip of mermaid chunks.
  • Verified in a real browser (light/dark, en/cn/pt-BR cross-build + understanding-lifetime, network check for the lazy chunk).

Real footnotes in the decision matrix

@void/md bundles markdown-it-footnote, but the matrix "footnotes" were plain unicode superscripts with a manual Notes list. They are now real [^1][^4] refs/definitions in all three locales: clickable superscripts in the table cells, backlinked footnote section, styled by the existing prose.css rules (same convention as /docs/deep-dive/native-module). Definition text is unchanged.

🤖 Generated with Claude Code

Brooooooklyn and others added 3 commits July 7, 2026 19:53
…land

@void/md has no mermaid support, so the cross-build decision tree and the
understanding-lifetime flowcharts SSR'd as plain highlighted code blocks.
Add a MermaidBlocks island ('load' in all three docs layout entries) that
renders null and, only when a page actually contains a language-mermaid
fence, lazy-imports mermaid (securityLevel strict, suppressErrorRendering)
and swaps each fence for the rendered SVG. The fence stays in the DOM
(hidden) as the re-render source and as the fallback on render failure.
Diagrams re-render on theme flips via a MutationObserver on the html
data-theme attribute, matching the site's dual .dark/data-theme signal.
Pages without diagrams only fetch the 1.2 KB gzip island chunk.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…de fence

Two adversarial-review findings:

- Remount idempotency: mounting over preserved DOM no longer stacks a
  second .mermaid-diagram host — the scan adopts an existing adjacent
  host, and the effect cleanup now removes owned hosts and restores each
  fence's pre-island inline display (remembered on the wrapper via
  data-mermaid-display) instead of only disconnecting the observer.

- Failure fallback: a per-block render failure now clears that block's
  host and reveals the original code fence, so a theme-toggle re-render
  failure can no longer leave a stale wrong-theme SVG on screen. Applied
  consistently for first renders and re-renders; other blocks are
  unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn merged commit 4413ccb into main Jul 7, 2026
2 checks passed
@Brooooooklyn Brooooooklyn deleted the mermaid-and-footnotes branch July 7, 2026 12:14
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