-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Trying to use programmatically, getting errors about DOMPurify #5204
Comments
i have a weird feeling the solution is this: https://github.com/kkomelin/isomorphic-dompurify |
in the mean time it might be viable look at how mermaid-cli does it https://github.com/mermaid-js/mermaid-cli/blob/master/src/index.js#L234 spoilers, they're running puppeteer first then executing mermaid inside the page they create. |
Hello, I have the same issue: the function mermaid.mermaidAPI.getDiagramFromText(graphData) returns the error "DOMPurify.addHook is not a function" when sending certain types of mermaid graphs. With basic graphs like this one: "graph TD; A-->B", it works. However, as soon as I add text on the links or try to add a description on the nodes, I get the aforementioned error. The code is executed on the server side with node.js. From what I understand, the getDiagramFromText function must use DOMPurify, which only works on the client side. I call the getDiagramFromText function to be able to retrieve a JavaScript object with the details of the nodes and transitions. Has anyone managed to work around this issue? Is this a new problem? Thank you in advance for your help, and congratulations to the contributors of this great project! |
I remember when I created the issue I changed some code to overcome the problem (I didn't need purification so I removed the calls to it), it was only a couple of places. IIRC, it was fairly simple to remove, so it should be possible to create a configuration option to disable the purification feature? I never read the actual source, just the library code that ships from npm, so take it with a grain of salt. |
Thank you for your feedback, MaddOg. I didn't understand how you managed to remove the call to DOMPurify. Do you mean that you modified the mermaid NPM package? |
Having the same issue - indirectly via mermaid-to-excalidraw, but still. Essentially, mermaid is not usable in nodejs server apps right now. A possible fix is hotpatching DOMPurify:
That possibly (haven't tried too hard) works for direct mermaid dependencies. It still doesn't fix the issue for packages the have a bundled mermaid. I strongly suspect that #5204 (comment) (isomorphic DOMPurify) is indeed the answer. |
Description
within a new typescript project, when trying to parse a diagram from text, I'm getting errors regarding DOMPurify - DOMPurify.addHook is not a function and DOMPurify.sanitize is not a function.
I'm suspecting it has something to do with the "module" configuration of typescript, but I'm not sure.
Steps to reproduce
package.json
tsconfig.json
index.ts
Screenshots
No response
Code Sample
No response
Setup
Suggested Solutions
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: