mjbvz / vscode-markdown-mermaid

Adds Mermaid diagram and flowchart support to VS Code's builtin markdown preview
https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid
MIT License
633 stars 114 forks source link

Upgrade mermaid to the latest version 10.0.2 #184

Closed shtratos closed 1 year ago

shtratos commented 1 year ago

Mermaid version 10.0.2 is the latest, but it has some breaking API changes.

I had to change the mermaid.render call as it no longer accepts a callback. see https://github.com/mermaid-js/mermaid/blob/master/CHANGELOG.md#1000

N.B. I tested the rendering and it works for correct graph, but it does not render parsing errors.

I see the following error in DevTools console whenever I try to render broken diagram:

 mermaid.core.mjs:202 36.409 : ERROR :  Error parsing Error: Diagram error not found.
    at Wt (utils-d5eeff82.js:2210:9)
    at new Nt (mermaidAPI-0716c7c2.js:384:21)
    at Object.render (mermaidAPI-0716c7c2.js:659:12)
(anonymous) @ mermaid.core.mjs:202
mermaid.core.mjs:165 36.409 : ERROR :  Error executing queue Error: Diagram error not found.
    at Wt (utils-d5eeff82.js:2210:9)
    at new Nt (mermaidAPI-0716c7c2.js:384:21)
    at Object.render (mermaidAPI-0716c7c2.js:659:12)
f @ mermaid.core.mjs:165
utils-d5eeff82.js:2210 Uncaught (in promise) Error: Diagram error not found.
    at Wt (utils-d5eeff82.js:2210:9)
    at new Nt (mermaidAPI-0716c7c2.js:384:21)
    at Object.render (mermaidAPI-0716c7c2.js:659:12)

This can be traced to this code in Diagram.ts and diagramAPI.ts

Not sure if this is a bug in Mermaid or if I'm calling it incorrectly. Any help would be appreciated.

shtratos commented 1 year ago

@sidharthv96 thank you, I've applied your recommendation but still running into an error. See the stacktraces above. Please have a look when you have time.

shtratos commented 1 year ago

btw, source maps do not work for me out of the box inside VSCode on Win11, so here's another branch with extra hacks to inline source maps. This allowed me to actually see where the error happens. https://github.com/shtratos/vscode-markdown-mermaid/compare/upgrade-to-mermaid-10...shtratos:vscode-markdown-mermaid:upgrade-to-mermaid-10-with-inline-sourcemaps

sidharthv96 commented 1 year ago

That error might be a mermaid bug. Will check that out.

mjbvz commented 1 year ago

Thank you for looking into this

I introduced some conflicts picking up 9.4. Because of this and because error rendering needed more attention, I've opened another PR that I think lets us upgrade to mermaid 10: #188

@shtratos Can you please help test out the new PR and see if everything looks ok