Skip to content

ui: draw Mermaid diagrams with Pele - #75

Draft
allozaur wants to merge 1 commit into
allozaur/perf/ui-import-costfrom
allozaur/perf/ui-pele-diagrams
Draft

allozaur wants to merge 1 commit into
allozaur/perf/ui-import-costfrom
allozaur/perf/ui-pele-diagrams

Conversation

@allozaur

@allozaur allozaur commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Overview

Llama Chat draws Mermaid diagrams with Pele instead of Mermaid.js. The app downloads a quarter less JavaScript at start (2.18 MB -> 1.62 MB gzipped), and diagrams now follow the light/dark theme switch.

Additional information

Part 12 of 13 of the work-in-progress stack on the fork, the top of it, based on allozaur/perf/ui-import-cost (#74), which found Mermaid and its dependencies to be the largest part of the bundle (~2.9 MB raw).

What changed
  • pele 1.13.0 (MIT, no dependencies, from obsidianmd) replaces mermaid 11.17.2, which drops 105 packages from the lockfile.
  • renderMermaidDiagrams() renders each pre.mermaid with Pele's synchronous render(), measuring labels with the block's own font after the page fonts load. On a narrow block (phones) Pele may turn a left-to-right flowchart top-to-bottom.
  • Colors come from --pele-* variables on :root in app.css, mapped to the theme tokens (code background, foreground, muted, border, primary, destructive). The SVG inherits them inline and inside the preview dialog's shadow root, so a theme switch recolors diagrams without a redraw. Mermaid baked its theme in at render time, so diagrams kept the old theme until the page reloaded.
  • A diagram Pele can't draw shows the parse error and the line it stopped at, as text in the block (Mermaid drew its own error graphic).
  • Downloading a diagram from the preview writes the current theme colors into the file, so it looks as it did on screen.
  • The renderer no longer takes a dark-mode flag; the Mermaid-only .mermaidTooltip rule is gone.
  • Storybook: MarkdownContent gets a Diagrams story (flowchart, sequence, state, pie and a broken one) whose play test checks that four diagrams draw and the broken one shows its error.

What's different from Mermaid.js, per Pele's compatibility page: its own layout engine (positions and edge paths differ), no Mermaid themes, no HTML labels, no ZenUML or other external plugins. All diagram types built into Mermaid 12.1.0 are supported; click links are filtered, callbacks ignored.

Numbers
#74 (Mermaid) This PR (Pele)
Boot JS bundle, raw 7.68 MB 5.27 MB
Boot JS bundle, gzip 2.18 MB 1.62 MB
Boot JS bundle, brotli 1.67 MB 1.28 MB

Mermaid was already behind import(), but bundleStrategy: 'single' inlines dynamic imports, so it shipped at boot. Pele stays behind import() too, so a later split build would load it only when a message has a diagram.

Testing
  • ui/apps/chat: npm run check (0 errors), npm run lint, the 1085 unit tests, the Storybook tests (115 files, 252 tests, the new Diagrams story included) and npm run build pass.
  • Client tests: all 72 files (382 tests) pass, run in two halves. The two unhandled Context "Tooltip.Provider" not found errors from dialog-focus-mobile happen on ui: drop the import costs that slowed Llama Chat's boot, tests and dev server #74 too.
  • In Storybook, on the Diagrams story: the flowchart, sequence, state and pie diagrams draw in the app's colors in dark and light mode, and switching the theme recolors them in place. At 375 px the flowchart turns top-to-bottom with no sideways page scroll. The broken diagram shows the parse error with its caret under the mistake. The preview dialog shows the diagram in the theme colors, and the downloaded svg carries the resolved colors.
  • Not checked: the live-preview Markdown editor's diagrams (same renderer, not opened) and a running llama-server.

Requirements

@allozaur
allozaur added this pull request to stack #72 November 17, 2026 09:39
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from a63445a to cec7d11 Compare November 17, 2026 10:31
@allozaur
allozaur removed this pull request from stack #72 November 17, 2026 11:15
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from cec7d11 to f72f04b Compare November 17, 2026 11:16
@allozaur
allozaur added this pull request to stack #76 November 17, 2026 11:16
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch 2 times, most recently from 8a4ddc8 to 80fb7ce Compare November 17, 2026 12:27
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch 3 times, most recently from f302c40 to c8213e9 Compare November 17, 2026 13:13
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch 2 times, most recently from c833ab9 to 56e3688 Compare November 17, 2026 13:26
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 56e3688 to 167c111 Compare November 17, 2026 13:44
@allozaur
allozaur removed this pull request from stack #76 November 17, 2026 13:44
@allozaur
allozaur added this pull request to stack #78 November 17, 2026 13:44
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 167c111 to 199749c Compare November 17, 2026 15:28
@allozaur
allozaur removed this pull request from stack #78 November 17, 2026 16:25
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 199749c to 5e1281f Compare November 17, 2026 16:26
@allozaur
allozaur added this pull request to stack #79 November 17, 2026 16:26
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 5e1281f to 68a3257 Compare November 17, 2026 16:42
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 68a3257 to 6bed2b6 Compare November 17, 2026 17:16
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch 2 times, most recently from b11d293 to dbf98cc Compare November 17, 2026 17:30
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from dbf98cc to 5838f8d Compare November 17, 2026 22:00
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 5838f8d to 858ff0f Compare November 17, 2026 22:05
allozaur added a commit that referenced this pull request Nov 17, 2026
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from 858ff0f to d4c1b0f Compare November 17, 2026 22:21
Assisted-by: Claude (Opus 5.5 Medium)
@allozaur
allozaur force-pushed the allozaur/perf/ui-pele-diagrams branch from d4c1b0f to a45e545 Compare November 17, 2026 22:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant