-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Click events not firing on v2.8.3 #901
Comments
I saw the item "click event only works by clicking on node text," but I tried that. No matter where I clicked I got no results (without commenting out the gantt bindFunctions). I performed some experiments with pure svg events, and if an click handler is placed on a tag (which is where mermaid places it), the entire tag gets click events, not just the text. And if I comment out the gantt bindFunctions, the entire node gets events. So I suspect if that accurate, it is not related. |
Yes, the anchor variant works as expected for click. I did test that. Based on my experiments for this bug I would expect the tooltip not to work in #891 either, but I didn't notice at the time. I was only interested in verifying I had the syntax correct by trying the url syntax. When I was debugging the code it looked as though the tooltip was put into the event functions in the same way that my own function for the click was put in. Both event handlers were overwritten or deleted or something by the second call to cb(). If you were using the url syntax the missing tooltip almost certainly related. |
That is correct, there are no tooltips displayed. After commenting out the second cb call, tooltip event listeners exist and seem to work. |
This has to do with the fix of issue #847 . It turns out that the click event could be used to create XSS attacks on a web site when the clicks are generated by user input. If you generate the diagrams yourself or by automation you can enable click events when initializing mermaid by setting the security level to loose. See https://mermaidjs.github.io/#/?id=special-note-regarding-version-82 |
If you look at my full source, you will see that security level is set to 'loose' in my call to init. As part of my debugging I checked the security level, and at least in the places I checked, it was set to 'loose'. I do not believe this is the cause of the problem. As a minor point, all the tests in the code regarding security level have something like
That allows anything except "strict" to be treated as not strict, including someone typo-ing "strict" as, say, "strit". It would be better to have the test be less forgiving, e.g.
If someone typos "strict" the application remains secure. As another minor point, it might be a good idea to add a method, say "allowClickEvents()", on config rather than exposing the raw config.securityLevel string. Then you don't have to repeat the test code everywhere. |
I have debugged this a bit more. The svg code is inserted into the page twice, once by flowDB and once by ganttDB. The cb function that is called twice is an anonymous function passed in to mermaidAPI.render:
In the first call to cb() the svgCode as given by the parsing of the graph is set on the element.InnerHTML. The "callback" function is undefined and is not called. The bindFunctions method is called on the flowDB object. This object has two functions in its funs[] array, which it dutifully sets on the appropriate svg elements. In the second call to cb() the same svgCode as given by the parsing of the graph is set on the element.InnerHTML. This wipes out the svg elements created in the first call, including their event bindings. The "callback" function is again undefined and is not called. The bindFunctions method is called on the ganttDB object. This object has zero functions in its funs[] array, so none get set. I am unclear as to the bigger, architectural picture here, but it would seem that just on the basis of the innerHTML being set twice with the same svg code, something has gotten muddled. My first thought is that the different calls to cb() should be in a switch statement based on graphType, as with earlier calls to setConf() and draw(). My second thought is that there should be a factory based on graphType instead, returning only one object that would have these methods on it. |
Thanks for doing such an in depth analysis of this. Was an easy fix after you had done the heavy lifting. Also switch ed the handling of the configured value to use !== 'loose' |
… Also sanitized the tooltips so that no tags are allowed in them for (#847).
Fixed with release 8.2.4 |
Hi guys, I have the next error with the click event when I try to run a function from some node from the mermaid diagram:
do you have any idea about that? my conf is the next: package.json:
index.html:
main.ts:
|
Describe the bug
Click events on a simple mermaid graph do not fire in v2.8.3. I have attached the full web page, but the core is a simple, two-node flowchart:
mermaid is initialized as below:
mermaid draws the flowchart correctly but the "show details" text does not appear on mouse over, and the showFullFirstSquad() method is not called on click.
The problem seems to be due to calling the cb() method in webpackAPI.render. This is the code from the webpack:
This code corresponds to two lines in mermaidAPI.render() on lines 500 & 501. I have commented out the second call to cb, and if I do that, the "show details" text appears on mouse over, and a click calls the method. As best I can tell, the first call to cb sets up the mouseover and click event handlers correctly, then the second call wipes out the working click handlers. I am not 100% sure but the second call may completely redraw the svg too.
This is running on ubuntu in firefox 68.0.1.
The full page:
index.txt
The text was updated successfully, but these errors were encountered: