Skip to content

Fix MermaidWithFallback diagram display #2609

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

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

pwizla
Copy link
Collaborator

@pwizla pwizla commented Jul 24, 2025

The diagrams were not properly loading when switching tabs, as seen on the Documents concept page. This PR fixes this issue.

Root cause: Mermaid.js cannot re-render on already processed DOM elements, and diagrams in hidden tabs weren't being rendered when those tabs became visible.

Solution:
Added proper Docusaurus tab visibility detection using getBoundingClientRect() and [role="tabpanel"] hidden attributes
Implemented event listeners for tab changes ([role="tab"] clicks and MutationObserver for hidden attribute changes)
Added clean DOM reset between renders to remove existing SVGs and mermaid-generated attributes
Improved timing with appropriate delays for tab switching (50ms) and theme changes (100ms)

Features preserved:

  • Download links functionality
  • Light/dark mode theme switching
  • Fallback to static images when rendering fails
  • Medium-zoom integration for fallback images

The diagrams now render correctly on the default tab, switch properly between tabs, and re-render when returning to previously visited tabs.

was not properly loading diagrams when switching tabs
@pwizla pwizla self-assigned this Jul 24, 2025
@pwizla pwizla added source: repo PRs/issues not targeting a specific documentation but rather affecting the whole repo pr: chore labels Jul 24, 2025
Copy link

vercel bot commented Jul 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2025 10:04am

@pwizla pwizla added this to the 6.6.5 milestone Jul 24, 2025
@pwizla pwizla merged commit 7e7ab7e into main Jul 24, 2025
14 checks passed
@pwizla pwizla deleted the repo/fix-mermaid-diagrams-display-in-tabs branch July 24, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: chore source: repo PRs/issues not targeting a specific documentation but rather affecting the whole repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant