-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
API crashes on 2nd render() call #478
Comments
I get the same thing but there doesnt appear to be a renderError (like there is for parseError) to override to inspect further. Its AspNetCore 1.1 mvc project if that is anything in common. <div class="row">
<div class="col-lg-3">
<textarea id="mermaidDataEntryField" class="mermaidDataEntryField" rows="10" cols="80">
graph TD
A-->B("<b>nice</b> <i>display</i> value")
B-->C["got it?"]
</textarea>
</div>
<div class="mermaidChartContainer col-lg-7">
<div class="row">
<text>Svg Preview</text>
</div>
<div class="row">
<div id="mermaidPreview" class="mermaid">
</div>
</div>
<div class="row">
<div id="errParse"></div>
</div>
</div>
</div>
<div class="row">
<div id="controls" class="row">
<input type="button" value="Force Preview" class="btn btn-primary" onclick="return attemptGraphRendering();" />
</div>
</div>
<script>
var mermaidInitted = false;
function attemptGraphRendering() {
if (mermaidInitted === false)
{
mermaid.init({ startOnLoad: false });
mermaid.parseError = function(err,hash){
$('#errParse').value(err);
};
mermaidInitted = true;
}
var ele = $('#mermaidDataEntryField');
var graphText = ele.val();
var parseable = mermaidAPI.parse(graphText);
if (parseable) {
var graph = mermaid.mermaidAPI.render(graphText);
$('#mermaidPreview').html(graph);
}
else{
$('#errParse').value("Couldn't parse");
}
}
</script> |
render can take 3 parameters. I faced the same problem and corrected it like that (I used Jquery but feel free to do it with JS) :
the value |
Fantastic, @trichetriche thanks! var needsUniqueId = "render" + (Math.floor(Math.random() * 10000)).toString(); //should be 10K attempts before repeat user finger stops working before then hopefully
mermaid.mermaidAPI.render(needsUniqueId, graphText, mermaidApiRenderCallback);
function mermaidApiRenderCallback(graph) {
$('#mermaidPreview').html(graph);
} |
Well, this does "fix" the bug, so thank you. Still I think it's absurd that some random id is required in order to generate an svg graph. I wish the API could just give me the svg code based on the markdown text I provide and append it my to div. |
I do agree with you @jansennetive, but I think it might come from a feature that we haven't used yet. |
@jansennetive consider reopening the issue |
This solution helps me : var needsUniqueId = "render" + (Math.floor(Math.random() * 10000)).toString(); //should be 10K attempts before repeat user finger stops working before then hopefully function mermaidApiRenderCallback(graph) { |
This still happens today with the latest version of Mermaid. Although it doesn't crash, unless I provide a unique ID, every ~3 or so renders will give me an empty SVG (Even though all the other inputs are the same) |
In Vue I am doing the following:
|
The reason why the id is required is that the DOM is used for rendering the svg even though that isn't visible. The id is used to reference the element. We could have a check in the render function, if there are two arguments, generate a uniq id. If there are three arguments assume the first one is a provided unique id. When implementing this, make sure the api docs are updated. They are generated from the comments in the mermaidAPI.js file. See the comments above the render function. This could be a good first issue. |
- remove element from DOM before rendering to avoid conflicts in case of rerendering
@chris579 Hey, Chris. I believe you looked into this issue. We received a PR for it. Could you check it out? Do you think it solves the issue? Are you currently working on it and would prefer merging what you have instead of the PR? |
I wasn't able to have a deep look into it but surely will look into that PR. |
- add e2e test for (re)rendering by api
- remove element from DOM before rendering to avoid conflicts in case of rerendering
- add e2e test for (re)rendering by api
Hey everyone,
I successfully set up my site to read input from a textarea and make it rerender with MermaidAPI.
The first time I change the input in the textarea, the graph changes as expected.
But the second time I change the textarea I get the following error:
The code I used is as follows:
I am baffled by this weird error and I can't find out what really caused it. Any ideas?
The text was updated successfully, but these errors were encountered: