Skip to content

Add support for mermaid.js diagrams. #1338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

Mpdreamz
Copy link
Member

@Mpdreamz Mpdreamz commented Jun 3, 2025

parcel barfs pretty hard on a regular import.

import mermaid from 'mermaid'

The following is the only way to make it 'work' with the main npm module but it being a esm tagetting browsers makes me think it shouldn't work.

import mermaid from 'mermaid/dist/mermaid.esm.min.mjs'

And while that works we we end up with a gazilion (200+) files in /_static

I therefor opted to depend on https://www.npmjs.com/package/@mermaid-js/tiny instead which is manually copied over to _static.

tiny is a bit of a misnomer its still 1.6mb so we only load these script if the page is actually using mermaid.

This does not support

  • Mindmap Diagram
  • Architecture Diagram
  • Katex rendering

Preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/1338/syntax/diagrams

cursorful-video-1748982940773.mp4

@Mpdreamz Mpdreamz requested a review from a team as a code owner June 3, 2025 18:52
@Mpdreamz Mpdreamz self-assigned this Jun 3, 2025
@Mpdreamz Mpdreamz changed the title feature/mermaid support Add support for mermaid.js diagrams. Jun 3, 2025
@reakaleek
Copy link
Member

I'm wondering why there is such a big lag until it renders the mermaid diagram.

@reakaleek
Copy link
Member

We might also want to explore lazy loading mermaid as a follow-up. Especially, if we need the full mermaid at some point.

@reakaleek
Copy link
Member

reakaleek commented Jun 4, 2025

IMO it would look nice to show something like a loading spinner or skeleton loader instead of the raw mermaid text.

@Mpdreamz
Copy link
Member Author

Mpdreamz commented Jun 4, 2025

I'm wondering why there is such a big lag until it renders the mermaid diagram.

Yeah this really stumped me too. The main distribution of mermaidjs does a lot of lazy loading of script resources at the expense of lags, here were including a special prebaked tiny distribution which shouldn't do that.

IMO it would look nice to show something like a loading spinner or skeleton loader instead of the raw mermaid text.

yeah this is needed before merging, it's not a great look otherwise.

@@ -0,0 +1,164 @@
# Diagrams

You can embedd diagrams using [mermaid.js](https://mermaid.js.org)
Copy link
Member

Choose a reason for hiding this comment

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

Should we also add here which diagrams are not supported? (and maybe why)

Copy link
Contributor

@theletterf theletterf Jun 4, 2025

Choose a reason for hiding this comment

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

Edited the docs right now

@theletterf
Copy link
Contributor

@Mpdreamz @reakaleek I wonder if switching to the neutral theme would be better for our docs theme and visual identity? https://mermaid.js.org/config/theming.html#available-themes

@theletterf
Copy link
Contributor

The slight rendering delay I notice in the video... Is this something we could avoid? Maybe through lazy loading (didn't check if we implement it)? Would loading Mermaid from the CDN help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants