facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
56.55k stars 8.49k forks source link

Mermaid diagrams do not render text nodes (empty `foreignObject`) #10526

Closed pwizla closed 1 month ago

pwizla commented 1 month ago

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Docusaurus 3.5.2 (but in my testings it's reproducible with many other, if not all, 3.x.x versions)

Mermaid diagrams are rendered with empty text nodes. foreignObject DOM nodes are empty.

Reproducible on new.docusaurus.io: https://codesandbox.io/p/devbox/dawn-darkness-docusaurus?privacy=public

Screenshot 2024-09-27 at 11 34 11

I'm in the process of upgrading to Docusaurus 3. Mermaid diagrams were working perfectly with Docusaurus v3.5.1 a few weeks ago. Today, they don't seem to work as expected with 3.5.x, and, weirdly enough, I can't have them work in any other 3.x.x version either, including versions that were previously rendering diagrams perfectly 🤔

Reproducible demo

https://codesandbox.io/p/devbox/dawn-darkness-docusaurus?privacy=public

Steps to reproduce

  1. Create new project
  2. Ensure mermaid theme is in the dependencies ("@docusaurus/theme-mermaid": "3.5.2",), and Mermaid is properly configured in docusaurus.config.js:

    markdown: {
      mermaid:  true,
    },
    
    themes: ['@docusaurus/theme-mermaid'],
    1. Insert a basic Mermaid diagram in a Markdown file, for instance at the top of the "Congratulations!" page in CodeSandbox. For instance like in the following excerpt:
    # Congratulations!
    
    You have just learned the **basics of Docusaurus** and made some changes to the **initial template**.
    
     ```mermaid
     graph TD
       A --> B
    
    
    4. Notice how the page renders the diagram but without any text, and inspect the DOM to notice that `foreignObject` nodes are empty, while they should contain text elements in a diagram properly rendered.

Expected behavior

Properly rendered diagram with text nodes It shouldn't be a Mermaid syntax issue because our original diagram, working on Docusaurus 2.xx and on our live website, is also working on mermaid.live.

Actual behavior

Empty text nodes:

Screenshot 2024-09-27 at 11 34 11

No error in the console (DevTools or server) 🤷

Your environment

Self-service

tramoni-vl commented 1 month ago

I'm having the same issue and it was even working yesterday 🤷🏻‍♂️ So maybe a dependency somewhere is causing the havoc

slorber commented 1 month ago

Note: your codesandbox is not a repro and doesn't contain any Mermaid-related code.

But I can reproduce on Stackblitz v3.5.2 with mermaid@10.9.1 dependency (latest 10.x)

It worked on our website under 10.4.0 and now that we upgraded to 11.2.1 (Docusaurus v3.6 soon) it keeps working so it is very likely a dependency that broke this but maybe not mermaid directly.

https://docusaurus.io/docs/markdown-features/diagrams#usage

tramoni-vl commented 1 month ago

Note: your codesandbox is not a repro and doesn't contain any Mermaid-related code.

But I can reproduce on Stackblitz v3.5.2 with mermaid@10.9.1 dependency (latest 10.x)

It worked on our website under 10.4.0 and now that we upgraded to 11.2.1 (Docusaurus v3.6 soon) it keeps working so it is very likely a dependency that broke this but maybe not mermaid directly.

https://docusaurus.io/docs/markdown-features/diagrams#usage

Yhea i suppose that if you try to rebuild your current working website at this date, the diagrams will do not show any texts

slorber commented 1 month ago

Indeed it's a bug in a transitive dependency that was released 1d ago.

DOMPurify v3.1.7 breaks Mermaid.

You can fix it by downgrading to v3.1.6 with package manager features, for example Yarn resolutions:

  "resolutions": {
    "dompurify": "3.1.6"
  },

I created issues here:

pwizla commented 1 month ago

Thank you very much, @slorber! Pinning dompurify to 3.1.6 worked for me 🥳 Would you like me to close this issue now, or shall we keep it open for reference and/or until DOMPurify 3.1.8 is released with the new option?

slorber commented 1 month ago

Np

We can keep it open until we are able to make it work by default for all newly initialized sites. We are waiting for Mermaid's position to figure out what to do.

Using yarn resolution works but we don't want to keep it this way forever, it's not good DX to have to ask users to do this.

slorber commented 1 month ago

Mermaid pinned the deps in https://github.com/mermaid-js/mermaid/releases/tag/v10.9.2

And a v11 release with this pinning is also planned (but Docusaurus only upgrades to v11 in the upcoming minor so we have time to wait).

The problem should be fixed for all Docusaurus sites <= v3.5 as long as they regenerate their lockfile or upgrade mermaid v10.x to latest.

Let me know if that works for you and if we can close

pwizla commented 1 month ago

Yay, this works! 🥳 Thank you and thanks Mermaid team! 🤗 I'm closing the issue now ✅