添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
博学的钢笔  ·  JS得到div ...·  4 周前    · 
好帅的山羊  ·  填报JS文档汇总- ...·  4 周前    · 
深情的黄瓜  ·  js获取button的状态 - ·  4 周前    · 
豪气的大葱  ·  DOE CODE GitLab ...·  3 月前    · 
讲道义的热水瓶  ·  Connectors - PandasAI·  3 月前    · 

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 importXML method throws rootElement already set error // Missing override in BpmnImporter.add importXML method throws rootElement already set error // Missing override in BpmnImporter.add MaxStroh opened this issue Apr 25, 2018 · 9 comments

Actual Behavior

  • When importing any diagram, we sometimes get an error. The Canvas module throws that the rootElement is already set.
  • I found out, that in the BpmnImporter add-method the method _canvas.setRootElement is called without an override = true as parameter. Is this behaviour correct?
  • If we check the element, the BpmnImporter want to add, it's correctly our Process_1 root element. The current rootElement set is an empty __implicitRoot object and without override = true this __implicitRoot won't be overridden when the BpmnImporter wants to add it and the importXml method cancels with an error.
  • Thrown error

    Error: rootElement already set, need to specify override
    Stack trace:
    Canvas.prototype.setRootElement@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/node_modules/diagram-js/lib/core/Canvas.js?:432:13
    BpmnImporter.prototype.add@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/BpmnImporter.js?:87:5
    root@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/Importer.js?:35:16
    visitRoot@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/BpmnTreeWalker.js?:78:12
    handleDefinitions@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/BpmnTreeWalker.js?:209:15
    render@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/Importer.js?:51:5
    importBpmnDiagram@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/import/Importer.js?:61:5
    Viewer.prototype.importDefinitions@webpack://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/Viewer.js?:315:10
    Viewer.prototype.importXML/< @webpack ://VBCP.%5Bname%5D/./node_modules/bpmn-js/lib/Viewer.js?:180:5
    XMLReader.prototype.fromXML/< @webpack ://VBCP.%5Bname%5D/./node_modules/moddle-xml/lib/reader.js?:825:5
    baseDelay/< @webpack ://VBCP.%5Bname%5D/./node_modules/lodash/internal/baseDelay.js?:18:34

    Steps to reproduce the Behavior

  • Bug/Error is not always reproducable, if so it is simply thrown when opening and importing some diagram
  • In our case a simple override = true fix the issue, but I'm not sure if this is expected behaviour, that no override is set at this point?!

    Our fix:
    BpmnImporter.prototype.add = function(semantic, parentElement) {

    var di = semantic.di,
    element,
    translate = this._translate,
    hidden;

    var parentIndex;

    // ROOT ELEMENT
    // handle the special case that we deal with a
    // invisible root element (process or collaboration)
    if (is(di, 'bpmndi:BPMNPlane')) {

    // add a virtual element (not being drawn)
    element = this._elementFactory.createRoot(elementData(semantic));
    this._canvas.setRootElement(element, **true** );
              

    Hey guys,

    While building a test case to show what our problem is, I saw the mistake in our code.
    Because of splitting our code into modules the importXML method is in a completely other module then the calls of the getRootElement methods or the accesses to the diagram elements. In our case, the diagram wasn't completely imported before the first time another module tried to get the rootElement.

    But because of the modularity of our probject we were not able to put all the following code into this one callback of the importXML method. This would have crashed our entire architecture.

    So today I found out, that there is an "import.done" event on which we can listen and wait for to ensure, that all elements are available when trying to get them. Is it recommendable to use this event? Or would you advise against listening on this event (maybe because it should be an internal used event only)? An alternative could maybe be to refactor the importXML function as an async function so we can await the result?

    And a question about the events: Do you have any documentations where we can read about all or at least the most relevant / useful events thrown by the bpmn-js lib? I think this would be veeeery very helpful (not only for us)!!! :) 👍

    So thank you for your help and time! I hope you can give us a few tips about best practices for this case :)

    Greetings,

    For what it's worth I was able to reproduce this error by creating the modeler and then trying to drag an item from the palette to the canvas before the call to "importXML" is made. When you try to drag an item from the palette to the canvas the canvas turns a light shade of red indicating that it is not allowed. The error occurs when you then try to load a BPMN document by making the call to "importXML".

    The error occurs due to the fact that you got a raise condition between importing (to setup the diagram) and your first modeling interaction.

    As a best practice, ensure you always show a diagram, e.g. by importing an EMPTY xml file.

    Makes sense. I only encountered the error while testing edge cases. I'm pulling the diagram XML from a backend data source and wanted to see the behavior if the call to retrieve the XML didn't succeed (and subsequently the importXML function never being called). Instead of loading an empty XML file I decided to hide the palette (CSS) until the call to importXML completed properly.

    Hi all,I am facing the same issue of Error: rootElement already set, need to specify override. well in my case i want to import an bpmn/xml file first and then add the custom elements with the xml file.This part is important for my case.As my project majorly revolves around custom-elements and interaction with xml file.
    Right now the fix can be of just changing the if condition in canvas.Js but i personally think this is not the right way.Kindly any update on this is highly appreciated
    thanks

    @AbdurRehman91 Please raise your matter in our forum. Clearly describe your use-case and what you'd like to achieve. Underline your description with examples that help us understand your case and we may be able to provide assistance.

    The check is there to avoid programming / library usage errors and I presume there is a proper way to implement what you'd like to achieve without monkey patching the library.