Skip to content

docs: Replace mermaid with reactflow-based diagram components#11770

Open
anthonyshew wants to merge 4 commits intomainfrom
feat/replace-mermaid-with-reactflow
Open

docs: Replace mermaid with reactflow-based diagram components#11770
anthonyshew wants to merge 4 commits intomainfrom
feat/replace-mermaid-with-reactflow

Conversation

@anthonyshew
Copy link
Contributor

@anthonyshew anthonyshew commented Feb 10, 2026

Summary

  • Removes the mermaid npm package and its ~20 transitive dependencies (including the vulnerable lodash-es@4.17.21)
  • Replaces it with custom diagram components built on reactflow, which is already a dependency used by the devtools page
  • Upgrades streamdown from v1 to v2, which drops its mermaid transitive dependency (net -91 packages from the lockfile)
  • Eliminates the lodash-es prototype pollution vulnerability (GHSA-xxjr-mmjv-4gpg / TURBO-5267) without needing a pnpm override

What changed

The old <Mermaid> component dynamically imported the full mermaid library to render SVGs client-side. The new implementation:

  1. Parses mermaid DSL at render time with lightweight custom parsers (~200 LOC each for flowcharts and sequence diagrams)
  2. Renders flowcharts via reactflow with auto-layout (DAG depth-based positioning) and direction-aware edge handles
  3. Renders sequence diagrams via pure SVG with theme-aware colors
  4. Detects diagram type automatically from the ```mermaid code block header
  5. Replaces the remark plugin — swaps remarkMdxMermaid from fumadocs-core with a custom one that produces the same <Mermaid chart="..." /> JSX output

Supported mermaid syntax:

  • Flowcharts: graph LR/TD/TB/RL/BT, node shapes (rect, round, circle, diamond, stadium, subroutine), edge styles (arrow, plain, dotted, thick), edge labels, subgraphs
  • Sequence diagrams: participants/actors, message styles (solid, dashed, open, cross), notes, blocks (loop, alt, opt, else)

How to test

A demo page is included at /docs/diagram-examples with flowcharts (simple, branching, node shapes, subgraphs, task graph) and sequence diagrams (request/response, cache flow with alt blocks, auth flow). Run pnpm dev --filter=docs and visit the page.

Closes TURBO-5267

Remove the mermaid dependency (~20 transitive deps including vulnerable
lodash-es) and replace it with custom diagram components built on top of
the reactflow library already in use by the devtools page.

New components:
- Flowchart parser supporting graph LR/TD, nodes, edges, labels, subgraphs
- Sequence diagram parser supporting participants, messages, notes, blocks
- FlowDiagram: reactflow-based renderer with auto-layout
- SequenceDiagram: SVG-based renderer with theme support
- Custom remark plugin replacing fumadocs remarkMdxMermaid

Also upgrades streamdown from v1 to v2, which drops its mermaid transitive
dependency (net -91 packages from lockfile).

Resolves TURBO-5267 (lodash-es prototype pollution vulnerability).
@anthonyshew anthonyshew requested a review from a team as a code owner February 10, 2026 15:30
@anthonyshew anthonyshew requested review from tknickman and removed request for a team February 10, 2026 15:30
@vercel vercel bot temporarily deployed to Preview – turborepo-test-coverage February 10, 2026 15:31 Inactive
@vercel
Copy link
Contributor

vercel bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples-basic-web Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-designsystem-docs Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-gatsby-web Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-kitchensink-blog Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-nonmonorepo Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-svelte-web Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-tailwind-web Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
examples-vite-web Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
turbo-site Ready Ready Preview, Comment, Open in v0 Feb 10, 2026 3:58pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
turborepo-test-coverage Skipped Skipped Open in v0 Feb 10, 2026 3:58pm

Edges were connecting to top/bottom handles regardless of graph direction,
causing ugly curved arcs in LR layouts. Now each edge specifies the correct
sourceHandle/targetHandle based on direction (LR uses right->left, TD uses
bottom->top, etc.).
@vercel vercel bot temporarily deployed to Preview – turborepo-test-coverage February 10, 2026 15:52 Inactive
@vercel vercel bot temporarily deployed to Preview – turborepo-test-coverage February 10, 2026 15:57 Inactive
@anthonyshew anthonyshew changed the title feat: Replace mermaid with reactflow-based diagram components docs: Replace mermaid with reactflow-based diagram components Feb 10, 2026
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