Skip to content

Render each mermaid diagram in its own derivation - #79

Merged
yuval-block merged 1 commit into
mainfrom
mermaid-cache
Oct 24, 2026
Merged

yuval-block merged 1 commit into
mainfrom
mermaid-cache

Conversation

@yuval-block

Copy link
Copy Markdown
Collaborator

Every diagram was rendered twice, by a chromium of its own, on every build of the site, and any change to a tracked file rebuilt the site.

nix/mermaid.nix now finds the mermaid blocks at evaluation time and renders each in a derivation whose only input is the diagram's text, with a placeholder for the svg id, so an edit elsewhere in the book renders nothing. mermaid_ssr.py takes the rendered svgs from MERMAID_SVG_DIR by the sha256 of their text and fills in the id, and fails on a block that nix did not find. Outside the nix build it still runs mmdc.

The site is built from a file set limited to what mdbook reads, so edits to the nix files, the tests or the dictionaries leave it cached.

Every diagram was rendered twice, by a chromium of its own, on every
build of the site, and any change to a tracked file rebuilt the site.

nix/mermaid.nix now finds the mermaid blocks at evaluation time and
renders each in a derivation whose only input is the diagram's text,
with a placeholder for the svg id, so an edit elsewhere in the book
renders nothing. mermaid_ssr.py takes the rendered svgs from
MERMAID_SVG_DIR by the sha256 of their text and fills in the id, and
fails on a block that nix did not find. Outside the nix build it still
runs mmdc.

The site is built from a file set limited to what mdbook reads, so
edits to the nix files, the tests or the dictionaries leave it cached.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yuval-block
yuval-block requested a review from bc1cindy October 23, 2026 23:37

@bc1cindy bc1cindy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 542405c

@yuval-block
yuval-block added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit 116e871 Oct 24, 2026
2 checks passed
@yuval-block
yuval-block deleted the mermaid-cache branch October 24, 2026 15:50
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.

3 participants