diff --git a/lib/Modeler.js b/lib/Modeler.js index 8e0a9bc..688a251 100644 --- a/lib/Modeler.js +++ b/lib/Modeler.js @@ -20,7 +20,8 @@ import BpmnDiOrdering from './features/di-ordering'; import ChoreoSpaceToolModule from './features/space-tool'; import { - displayChoreography + displayChoreography, + clearShapeCache } from './import/ImportHandler'; @@ -39,6 +40,11 @@ Modeler.prototype.open = function(bpmnDiagramOrId) { return displayChoreography(this, bpmnDiagramOrId); }; +Modeler.prototype.importXML = function(xml, bpmnDiagram) { + clearShapeCache(); + return BaseModeler.prototype.importXML.call(this, xml, bpmnDiagram); +}; + Modeler.prototype.clear = function() { // Skip clearing of the DI references introduced in this commit by bpmn-js: // https://github.com/bpmn-io/bpmn-js/commit/0c71ad30a0c945679851e73b15647f634f2b9bb8 diff --git a/lib/Viewer.js b/lib/Viewer.js index 25c158e..df089de 100644 --- a/lib/Viewer.js +++ b/lib/Viewer.js @@ -6,7 +6,8 @@ import inherits from 'inherits'; import CoreModule from './core'; import { - displayChoreography + displayChoreography, + clearShapeCache } from './import/ImportHandler'; @@ -35,6 +36,11 @@ Viewer.prototype.open = function(bpmnDiagramOrId) { return displayChoreography(this, bpmnDiagramOrId); }; +Viewer.prototype.importXML = function(xml, bpmnDiagram) { + clearShapeCache(); + return BaseViewer.prototype.importXML.call(this, xml, bpmnDiagram); +}; + Viewer.prototype.clear = function() { // Skip clearing of the DI references introduced in this commit by bpmn-js: // https://github.com/bpmn-io/bpmn-js/commit/0c71ad30a0c945679851e73b15647f634f2b9bb8 diff --git a/lib/import/ImportHandler.js b/lib/import/ImportHandler.js index 6bb78a6..af02cbf 100644 --- a/lib/import/ImportHandler.js +++ b/lib/import/ImportHandler.js @@ -1,5 +1,13 @@ let shapeCache = {}; +/** + * Clear the cached shapes. This function should be called when loading a new diagram, + * since the old cache might lead to errors if elements with the same IDs are encountered. + */ +export function clearShapeCache() { + shapeCache = {}; +} + /** * Display a specific choreography contained in the definitions attached to a viewer. *