Mermaid with ReactMarkdown & Next.js #4251
-
Hey all, I am writing a doc app that uses Next.js, TypeScript, & ReactMarkdown. I added this script inside a div that also contains my ReactMarkdown component: <Script
type="module"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs";
mermaid.initialize({startOnLoad: true});
mermaid.contentLoaded();`,
}}
/> I'm having issues getting all of the figures I need to render. I believe this is a versioning problem, since when I change l.6 to <div class="mermaid">
erDiagram
ATLAS-ORGANIZATION ||--|{ ATLAS-PROJECTS : "has many"
ATLAS-PROJECTS ||--|{ MONGODB-CLUSTERS : "has many"
ATLAS-PROJECTS ||--|{ ATLAS-TEAMS : "has many"
MONGODB-CLUSTERS ||..|{
ATLAS-TEAMS ||..|{
</div> If I change the version to @9, I get this error message: If I change it to @10, I get just blank white space where the diagram would be. This is where it gets tricky- I need to support this type of diagram as well, but it doesn't render at all, and there is no error message, for the version numbers 8, 9, 10, & 10.0.2: <div class="mermaid">
flowchart TB
style team fill:#9F69C4,color:#fff
style pagerduty fill:#33FF42
team[Service team] --> pagerduty[1. PagerDuty<br/>incident response service]
team --> backstage[2. Backstage<br/>catalog]
click pagerduty "../incident-ready/pagerduty" _self
click backstage "../incident-ready/backstage" _self
</div> I tested this on mermaid.live & it works:
PS: I tried implementing remark-mermaid with these options, but got stuck at this error message: "Module not found: Can't resolve 'fs'" [remarkMermaid,
{
launchOptions: {
executablePath: "path/to/chrome/executable",
},
errorFallback: "file",
},
], |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi Celine,
I tried with vanilla HTML and it works. Try if removing the
One of Mermaid's core principles is to not break compatibility with diagrams between versions. So all diagrams should be supported in new versions. The erDiagram issue is a bug, which needs to be investigated. You could try to use different selector classes https://mermaid.js.org/config/usage.html#using-mermaid-run to support multiple versions. But I can't guarantee it'll work. |
Beta Was this translation helpful? Give feedback.
-
Here is next js code I am not able to render the following mermaid im not able to render the mermaid diagram using next js Unhandled Runtime Error Here is the code ``
|
Beta Was this translation helpful? Give feedback.
Hi Celine,
I tried with vanilla HTML and it works. Try if removing the
<br/>
helps with the flowchart.https://stackblitz.com/edit/web-platform-i3pncs?file=index.html
One of Mermaid's core principles is to not break compatibility with diagrams between versions. So all diagrams should be supported in new versions. The erDiagram issue is a bug, which needs to be investigated.
You could try to use different selector classes https://merm…