Skip to content

ux: improve Mermaid rendering and theme switching - #26304

Merged
akristen merged 2 commits into
docker:mainfrom
akristen:mermaid-style
Oct 8, 2026
Merged

akristen merged 2 commits into
docker:mainfrom
akristen:mermaid-style

Conversation

@akristen

@akristen akristen commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Problem: Mermaid diagrams briefly showed their raw source before the SVG appeared, stayed on the wrong palette after a light/dark theme toggle, and could leave Mermaid's error graphic in the page when a diagram failed to parse.

Why this change: Diagrams are used more often in the docs, so the renderer needs to match the site theme and avoid flashing source text while SVGs load.

Solution: Replace mermaid.run() with a controlled mermaid.render() loop that caches each block's source, skips stale async results, re-renders when the <html> dark class changes, suppresses Mermaid's default error SVG, and hides pre.mermaid until an SVG is present (or a render error sets data-error so the source can still be inspected).

@netlify /get-started/docker-concepts/the-basics/what-is-a-registry/

Preview: https://deploy-preview-26304--docsdocker.netlify.app/get-started/docker-concepts/the-basics/what-is-a-registry/
Example of pre-fix behavior: https://deploy-preview-26283--docsdocker.netlify.app/accounts/organization/

Generated by Cursor

Hide diagram source until the SVG is ready, re-render on light/dark
theme changes, and avoid stale renders overwriting a newer theme.

Co-authored-by: Cursor <cursoragent@cursor.com>
@netlify

netlify Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit 2ea1355
🔍 Latest deploy log https://app.netlify.com/projects/docsdocker/deploys/6ac7b25f0382e50008879b3b
😎 Deploy Preview https://deploy-preview-26304--docsdocker.netlify.app/get-started/docker-concepts/the-basics/what-is-a-registry/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the hugo Updates related to hugo label Oct 7, 2026
@akristen
akristen requested a review from dvdksn October 7, 2026 13:49
@akristen akristen self-assigned this Oct 7, 2026
Comment thread assets/css/components.css Outdated
/* Mermaid blocks hold the diagram source until mermaid.js replaces it with
an SVG. Hide the source while that happens, unless rendering failed. */
pre.mermaid:not(:has(svg)):not([data-error]) {
display: none;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This rule loses to the Mermaid block’s flex utility because Tailwind’s utilities layer takes precedence over components, regardless of selector specificity.

I reproduced this in Chromium by blocking mermaid.js in the preview: the raw source remains visible with computed display: flex. Moving this rule outside the cascade layers changes it to display: none.

Could you move the rule outside @layer components and verify with Mermaid’s script delayed?

Generated by Codex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dvdksn I believe I addressed this in 2ea1355. I tested locally and on the netlify preview (blocked mermaid.js > didn't render anything > unblocked it > rendered w/o flickering). LMK if I need to fix anything else (or if this is the wrong solution~) thank you!

The rule hid pre.mermaid until an SVG was present, but it sat inside @layer components while the element carries Tailwind's flex utility. Cascade layers rank utilities above components regardless of selector specificity, so the source stayed visible with display: flex.

Unlayered styles win over every layer, so the rule now lives outside the layer block.

Co-authored-by: Cursor <cursoragent@cursor.com>
@akristen
akristen merged commit e448897 into docker:main Oct 8, 2026
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hugo Updates related to hugo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants