mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Merge pull request #994 from edekadigital/bug-478
#478 API crashes on 2nd render() call
This commit is contained in:
commit
0ce42e6185
16
cypress/integration/other/rerender.spec.js
Normal file
16
cypress/integration/other/rerender.spec.js
Normal file
@ -0,0 +1,16 @@
|
||||
/* eslint-env jest */
|
||||
describe('Rerendering', () => {
|
||||
|
||||
it('should be able to render and rerender a graph via API', () => {
|
||||
const url = 'http://localhost:9000/rerender.html';
|
||||
cy.viewport(1440, 1024);
|
||||
cy.visit(url);
|
||||
cy.get('#graph #A').should('have.text', 'XMas');
|
||||
|
||||
cy.get('body')
|
||||
.find('#rerender')
|
||||
.click({ force: true });
|
||||
|
||||
cy.get('#graph #A').should('have.text', 'Saturday');
|
||||
});
|
||||
});
|
33
cypress/platform/rerender.html
Normal file
33
cypress/platform/rerender.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Mermaid Quick Test Page</title>
|
||||
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
|
||||
</head>
|
||||
<body>
|
||||
<div id="graph">
|
||||
</div>
|
||||
|
||||
<script src="./mermaid.js"></script>
|
||||
<script>
|
||||
|
||||
mermaid.init({ startOnLoad: false });
|
||||
mermaid.mermaidAPI.initialize();
|
||||
|
||||
rerender('XMas');
|
||||
|
||||
function rerender(text) {
|
||||
var graphText = `graph TD
|
||||
A[${text}] -->|Get money| B(Go shopping)`
|
||||
var graph = mermaid.mermaidAPI.render('id', graphText);
|
||||
console.log('\x1b[35m%s\x1b[0m', '>> graph', graph)
|
||||
document.getElementById('graph').innerHTML=graph;
|
||||
}
|
||||
|
||||
</script>
|
||||
<button id="rerender" onclick="rerender('Saturday')">Rerender</button>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -463,6 +463,10 @@ const render = function(id, txt, cb, container) {
|
||||
.attr('xmlns', 'http://www.w3.org/2000/svg')
|
||||
.append('g');
|
||||
} else {
|
||||
const existingSvg = document.getElementById(id);
|
||||
if (existingSvg) {
|
||||
existingSvg.remove();
|
||||
}
|
||||
const element = document.querySelector('#' + 'd' + id);
|
||||
if (element) {
|
||||
element.innerHTML = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user