Skip to content

Commit feb5c37

Browse files
authored
Mermaid improvements (#4910)
* Phase 1 of Mermaid improvements * Phase 1 of Mermaid improvements
1 parent ed40028 commit feb5c37

5 files changed

Lines changed: 434 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ test-results/*
5353
screenshots
5454
# Ignore cookbook recipes since they are synced from the remote repo
5555
ai-cookbook
56+
scripts/mermaid-compare/*

docs/design-patterns/local-activities.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ sequenceDiagram
2222
participant S as Temporal Server
2323
2424
rect rgb(230, 235, 250)
25-
Note over W,S: Regular Activity — server round-trips on each call
25+
Note over W,S: Regular Activity —<br/>server round-trips on each call
2626
W->>S: Schedule ActivityTask
2727
S-->>W: Dispatch ActivityTask
2828
W->>W: Execute activity
@@ -31,7 +31,7 @@ sequenceDiagram
3131
end
3232
3333
rect rgb(220, 245, 225)
34-
Note over W,S: Local Activity — runs in-process, zero server calls
34+
Note over W,S: Local Activity —<br/>runs in-process, zero server calls
3535
W->>W: Execute activity function directly
3636
Note over W: Result bundled in WorkflowTask completion
3737
end

docusaurus.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const FontPreloadPlugin = require('webpack-font-preload-plugin');
33
const { prismDarkTheme, prismLightTheme } = require('./src/prismThemes');
44
const { ALGOLIA_APP_ID, ALGOLIA_SEARCH_API_KEY, ALGOLIA_INDEX_NAME } = require('./src/constants/algolia');
5+
const mermaidTheme = require('./src/constants/mermaidTheme');
56

67
/** @type {import('@docusaurus/types').DocusaurusConfig} */
78

@@ -225,6 +226,15 @@ module.exports = async function createConfigAsync() {
225226
],
226227
},
227228
},
229+
mermaid: {
230+
theme: mermaidTheme.theme,
231+
options: {
232+
themeVariables: { fontFamily: mermaidTheme.fontFamily },
233+
flowchart: mermaidTheme.flowchart,
234+
sequence: mermaidTheme.sequence,
235+
state: mermaidTheme.state,
236+
},
237+
},
228238
},
229239
presets: [
230240
[

src/constants/mermaidTheme.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Single source of truth for Mermaid diagram layout/typography, used by
2+
// docusaurus.config.js (themeConfig.mermaid.options) and by the dev-only
3+
// diagram review tool (scripts/mermaid-compare/, regenerate its
4+
// mermaid-theme.json from this file after editing it).
5+
//
6+
// These are mode-independent (no colors) because Docusaurus applies
7+
// `themeConfig.mermaid.options` identically in light and dark mode; only
8+
// `themeConfig.mermaid.theme.{light,dark}` (a built-in theme name) varies by
9+
// color mode. Brand colors are handled separately via CSS overrides in
10+
// src/css/custom.css targeting Mermaid's generated SVG classes, which is not
11+
// subject to that light/dark limitation — see the comment there for why.
12+
module.exports = {
13+
// Kept mode-aware (matching Docusaurus's own default) rather than pinned
14+
// to a single base theme, as a safety net for anything custom.css's
15+
// Mermaid overrides don't explicitly recolor (e.g. rarely-used elements
16+
// like the sequenceNumber marker) — verified those still need Mermaid's
17+
// own light/dark split to stay correct, not just the CSS layer.
18+
theme: { light: 'default', dark: 'dark' },
19+
fontFamily: '"Aeonik", "Poppins", -apple-system, BlinkMacSystemFont, sans-serif',
20+
flowchart: {
21+
padding: 14,
22+
nodeSpacing: 45,
23+
rankSpacing: 60,
24+
curve: 'basis',
25+
htmlLabels: true,
26+
wrap: true,
27+
},
28+
sequence: {
29+
actorMargin: 60,
30+
messageMargin: 40,
31+
boxMargin: 12,
32+
noteMargin: 12,
33+
// NOT wrap: true — Mermaid mis-sizes the note/message box width whenever
34+
// the text already has explicit <br/> breaks (a common pattern in these
35+
// diagrams) while wrap is on, at any font size: the box comes out
36+
// narrower than the actual rendered text, so text overflows its own
37+
// box. Confirmed by direct comparison; flowchart's `wrap` does not have
38+
// this problem (only sequence). Long single-line messages without <br/>
39+
// just render unwrapped (no auto line-break) instead — worse for that
40+
// one case, but the halo on .messageText already keeps unwrapped text
41+
// readable where it crosses a line, whereas a mis-sized note box is a
42+
// correctness bug with no equivalent mitigation.
43+
mirrorActors: false,
44+
},
45+
state: {
46+
padding: 14,
47+
},
48+
};

0 commit comments

Comments
 (0)