From 069b4854f8ff6ef3bb3a810f9f32d1de80744b7c Mon Sep 17 00:00:00 2001 From: Kolja Markwardt Date: Tue, 15 Oct 2019 08:02:41 +0200 Subject: [PATCH 1/2] #478 API crashes on 2nd render() call - remove element from DOM before rendering to avoid conflicts in case of rerendering --- src/mermaidAPI.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mermaidAPI.js b/src/mermaidAPI.js index a75fe6dbf..54fac25a8 100644 --- a/src/mermaidAPI.js +++ b/src/mermaidAPI.js @@ -462,6 +462,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 = ''; From d743838716fac63df23f1d2e897eeaa5a5f3bda3 Mon Sep 17 00:00:00 2001 From: Kolja Markwardt Date: Tue, 15 Oct 2019 17:05:20 +0200 Subject: [PATCH 2/2] #478 API crashes on 2nd render() call - add e2e test for (re)rendering by api --- cypress/integration/other/rerender.spec.js | 16 +++++++++++ cypress/platform/rerender.html | 33 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 cypress/integration/other/rerender.spec.js create mode 100644 cypress/platform/rerender.html diff --git a/cypress/integration/other/rerender.spec.js b/cypress/integration/other/rerender.spec.js new file mode 100644 index 000000000..d7b3d2b47 --- /dev/null +++ b/cypress/integration/other/rerender.spec.js @@ -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'); + }); +}); diff --git a/cypress/platform/rerender.html b/cypress/platform/rerender.html new file mode 100644 index 000000000..8a9c0424c --- /dev/null +++ b/cypress/platform/rerender.html @@ -0,0 +1,33 @@ + + + + + + Mermaid Quick Test Page + + + +
+
+ + + + + + +