Dynamically clearing canvas and save error

I have tried bpmnModeler.clear(); and it is sucessful clearing the canvas
but when I try to save the empty canvas as xml, its throwing below error

bpmn-modeler.development.js:5392 TypeError: Cannot read property 'set' of undefined at orderDi (VM53659 bpmn-modeler.development.js:44821) at invokeFunction (VM53659 bpmn-modeler.development.js:5526) at EventBus._invokeListener (VM53659 bpmn-modeler.development.js:5377) at EventBus._invokeListeners (VM53659 bpmn-modeler.development.js:5362) at EventBus.fire (VM53659 bpmn-modeler.development.js:5323) at Modeler.BaseViewer._emit (VM53659 bpmn-modeler.development.js:14774) at VM53659 bpmn-modeler.development.js:14484 at new Promise (<anonymous>) at Modeler.saveXML (VM53659 bpmn-modeler.development.js:14475) at Modeler.saveXML (VM53659 bpmn-modeler.development.js:14059)

What would be your expected result of exporting after clearing the diagram?

added the below code after clear and it solved my issue